Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
f87bd25f
Commit
f87bd25f
authored
14 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
In pg_upgrade, report /bin directory checks independent of /data checks.
parent
bae82835
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
contrib/pg_upgrade/exec.c
+80
-86
80 additions, 86 deletions
contrib/pg_upgrade/exec.c
with
80 additions
and
86 deletions
contrib/pg_upgrade/exec.c
+
80
−
86
View file @
f87bd25f
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
* execution functions
* execution functions
*
*
* Copyright (c) 2010, PostgreSQL Global Development Group
* Copyright (c) 2010, PostgreSQL Global Development Group
* $PostgreSQL: pgsql/contrib/pg_upgrade/exec.c,v 1.
8
2010/07/
06 19:18
:55 momjian Exp $
* $PostgreSQL: pgsql/contrib/pg_upgrade/exec.c,v 1.
9
2010/07/
13 18:09
:55 momjian Exp $
*/
*/
#include
"pg_upgrade.h"
#include
"pg_upgrade.h"
...
@@ -13,10 +13,10 @@
...
@@ -13,10 +13,10 @@
#include
<grp.h>
#include
<grp.h>
static
void
checkBinDir
(
migratorContext
*
ctx
,
ClusterInfo
*
cluster
);
static
void
check_data_dir
(
migratorContext
*
ctx
,
const
char
*
pg_data
);
static
void
check_bin_dir
(
migratorContext
*
ctx
,
ClusterInfo
*
cluster
);
static
int
check_exec
(
migratorContext
*
ctx
,
const
char
*
dir
,
const
char
*
cmdName
);
static
int
check_exec
(
migratorContext
*
ctx
,
const
char
*
dir
,
const
char
*
cmdName
);
static
const
char
*
validate_exec
(
const
char
*
path
);
static
const
char
*
validate_exec
(
const
char
*
path
);
static
int
check_data_dir
(
migratorContext
*
ctx
,
const
char
*
pg_data
);
/*
/*
...
@@ -55,6 +55,34 @@ exec_prog(migratorContext *ctx, bool throw_error, const char *fmt,...)
...
@@ -55,6 +55,34 @@ exec_prog(migratorContext *ctx, bool throw_error, const char *fmt,...)
}
}
/*
* is_server_running()
*
* checks whether postmaster on the given data directory is running or not.
* The check is performed by looking for the existence of postmaster.pid file.
*/
bool
is_server_running
(
migratorContext
*
ctx
,
const
char
*
datadir
)
{
char
path
[
MAXPGPATH
];
int
fd
;
snprintf
(
path
,
sizeof
(
path
),
"%s/postmaster.pid"
,
datadir
);
if
((
fd
=
open
(
path
,
O_RDONLY
,
0
))
<
0
)
{
if
(
errno
!=
ENOENT
)
pg_log
(
ctx
,
PG_FATAL
,
"
\n
could not open file
\"
%s
\"
for reading
\n
"
,
path
);
return
false
;
}
close
(
fd
);
return
true
;
}
/*
/*
* verify_directories()
* verify_directories()
*
*
...
@@ -67,21 +95,62 @@ void
...
@@ -67,21 +95,62 @@ void
verify_directories
(
migratorContext
*
ctx
)
verify_directories
(
migratorContext
*
ctx
)
{
{
prep_status
(
ctx
,
"Checking old data directory (%s)"
,
ctx
->
old
.
pgdata
);
prep_status
(
ctx
,
"Checking old data directory (%s)"
,
ctx
->
old
.
pgdata
);
if
(
check_data_dir
(
ctx
,
ctx
->
old
.
pgdata
)
!=
0
)
check_data_dir
(
ctx
,
ctx
->
old
.
pgdata
);
pg_log
(
ctx
,
PG_FATAL
,
"Failed
\n
"
);
check_ok
(
ctx
);
checkBinDir
(
ctx
,
&
ctx
->
old
);
prep_status
(
ctx
,
"Checking old bin directory (%s)"
,
ctx
->
old
.
bindir
);
check_bin_dir
(
ctx
,
&
ctx
->
old
);
check_ok
(
ctx
);
check_ok
(
ctx
);
prep_status
(
ctx
,
"Checking new data directory (%s)"
,
ctx
->
new
.
pgdata
);
prep_status
(
ctx
,
"Checking new data directory (%s)"
,
ctx
->
new
.
pgdata
);
if
(
check_data_dir
(
ctx
,
ctx
->
new
.
pgdata
)
!=
0
)
check_data_dir
(
ctx
,
ctx
->
new
.
pgdata
);
pg_log
(
ctx
,
PG_FATAL
,
"Failed
\n
"
);
check_ok
(
ctx
);
checkBinDir
(
ctx
,
&
ctx
->
new
);
prep_status
(
ctx
,
"Checking new bin directory (%s)"
,
ctx
->
new
.
bindir
);
check_bin_dir
(
ctx
,
&
ctx
->
new
);
check_ok
(
ctx
);
check_ok
(
ctx
);
}
}
/*
/*
* checkBinDir()
* check_data_dir()
*
* This function validates the given cluster directory - we search for a
* small set of subdirectories that we expect to find in a valid $PGDATA
* directory. If any of the subdirectories are missing (or secured against
* us) we display an error message and exit()
*
*/
static
void
check_data_dir
(
migratorContext
*
ctx
,
const
char
*
pg_data
)
{
char
subDirName
[
MAXPGPATH
];
int
subdirnum
;
const
char
*
requiredSubdirs
[]
=
{
"base"
,
"global"
,
"pg_clog"
,
"pg_multixact"
,
"pg_subtrans"
,
"pg_tblspc"
,
"pg_twophase"
,
"pg_xlog"
};
for
(
subdirnum
=
0
;
subdirnum
<
sizeof
(
requiredSubdirs
)
/
sizeof
(
requiredSubdirs
[
0
]);
++
subdirnum
)
{
struct
stat
statBuf
;
snprintf
(
subDirName
,
sizeof
(
subDirName
),
"%s/%s"
,
pg_data
,
requiredSubdirs
[
subdirnum
]);
if
(
stat
(
subDirName
,
&
statBuf
)
!=
0
)
report_status
(
ctx
,
PG_FATAL
,
"check for %s failed: %s"
,
requiredSubdirs
[
subdirnum
],
getErrorText
(
errno
));
else
if
(
!
S_ISDIR
(
statBuf
.
st_mode
))
report_status
(
ctx
,
PG_FATAL
,
"%s is not a directory"
,
requiredSubdirs
[
subdirnum
]);
}
}
/*
* check_bin_dir()
*
*
* This function searches for the executables that we expect to find
* This function searches for the executables that we expect to find
* in the binaries directory. If we find that a required executable
* in the binaries directory. If we find that a required executable
...
@@ -89,7 +158,7 @@ verify_directories(migratorContext *ctx)
...
@@ -89,7 +158,7 @@ verify_directories(migratorContext *ctx)
* exit().
* exit().
*/
*/
static
void
static
void
check
BinD
ir
(
migratorContext
*
ctx
,
ClusterInfo
*
cluster
)
check
_bin_d
ir
(
migratorContext
*
ctx
,
ClusterInfo
*
cluster
)
{
{
check_exec
(
ctx
,
cluster
->
bindir
,
"postgres"
);
check_exec
(
ctx
,
cluster
->
bindir
,
"postgres"
);
check_exec
(
ctx
,
cluster
->
bindir
,
"psql"
);
check_exec
(
ctx
,
cluster
->
bindir
,
"psql"
);
...
@@ -98,34 +167,6 @@ checkBinDir(migratorContext *ctx, ClusterInfo *cluster)
...
@@ -98,34 +167,6 @@ checkBinDir(migratorContext *ctx, ClusterInfo *cluster)
}
}
/*
* is_server_running()
*
* checks whether postmaster on the given data directory is running or not.
* The check is performed by looking for the existence of postmaster.pid file.
*/
bool
is_server_running
(
migratorContext
*
ctx
,
const
char
*
datadir
)
{
char
path
[
MAXPGPATH
];
int
fd
;
snprintf
(
path
,
sizeof
(
path
),
"%s/postmaster.pid"
,
datadir
);
if
((
fd
=
open
(
path
,
O_RDONLY
,
0
))
<
0
)
{
if
(
errno
!=
ENOENT
)
pg_log
(
ctx
,
PG_FATAL
,
"
\n
could not open file
\"
%s
\"
for reading
\n
"
,
path
);
return
false
;
}
close
(
fd
);
return
true
;
}
/*
/*
* check_exec()
* check_exec()
*
*
...
@@ -264,50 +305,3 @@ validate_exec(const char *path)
...
@@ -264,50 +305,3 @@ validate_exec(const char *path)
return
NULL
;
return
NULL
;
#endif
#endif
}
}
/*
* check_data_dir()
*
* This function validates the given cluster directory - we search for a
* small set of subdirectories that we expect to find in a valid $PGDATA
* directory. If any of the subdirectories are missing (or secured against
* us) we display an error message and exit()
*
*/
static
int
check_data_dir
(
migratorContext
*
ctx
,
const
char
*
pg_data
)
{
char
subDirName
[
MAXPGPATH
];
const
char
*
requiredSubdirs
[]
=
{
"base"
,
"global"
,
"pg_clog"
,
"pg_multixact"
,
"pg_subtrans"
,
"pg_tblspc"
,
"pg_twophase"
,
"pg_xlog"
};
bool
fail
=
false
;
int
subdirnum
;
for
(
subdirnum
=
0
;
subdirnum
<
sizeof
(
requiredSubdirs
)
/
sizeof
(
requiredSubdirs
[
0
]);
++
subdirnum
)
{
struct
stat
statBuf
;
snprintf
(
subDirName
,
sizeof
(
subDirName
),
"%s/%s"
,
pg_data
,
requiredSubdirs
[
subdirnum
]);
if
((
stat
(
subDirName
,
&
statBuf
))
!=
0
)
{
report_status
(
ctx
,
PG_WARNING
,
"check for %s warning: %s"
,
requiredSubdirs
[
subdirnum
],
getErrorText
(
errno
));
fail
=
true
;
}
else
{
if
(
!
S_ISDIR
(
statBuf
.
st_mode
))
{
report_status
(
ctx
,
PG_WARNING
,
"%s is not a directory"
,
requiredSubdirs
[
subdirnum
]);
fail
=
true
;
}
}
}
return
(
fail
)
?
-
1
:
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment