2010-05-12 10:19:11 +08:00
|
|
|
/*
|
|
|
|
* pg_upgrade.h
|
2010-07-03 22:23:14 +08:00
|
|
|
*
|
2013-01-02 06:15:01 +08:00
|
|
|
* Copyright (c) 2010-2013, PostgreSQL Global Development Group
|
2010-09-21 04:08:53 +08:00
|
|
|
* contrib/pg_upgrade/pg_upgrade.h
|
2010-05-12 10:19:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include "libpq-fe.h"
|
|
|
|
|
2011-07-02 06:17:12 +08:00
|
|
|
/* Use port in the private/dynamic port number range */
|
|
|
|
#define DEF_PGUPORT 50432
|
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
/* Allocate for null byte */
|
|
|
|
#define USER_NAME_SIZE 128
|
|
|
|
|
|
|
|
#define MAX_STRING 1024
|
|
|
|
#define LINE_ALLOC 4096
|
|
|
|
#define QUERY_ALLOC 8192
|
2010-07-07 03:19:02 +08:00
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
#define MIGRATOR_API_VERSION 1
|
|
|
|
|
2012-12-08 01:26:13 +08:00
|
|
|
#define MESSAGE_WIDTH 60
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
#define GET_MAJOR_VERSION(v) ((v) / 100)
|
|
|
|
|
|
|
|
/* contains both global db information and CREATE DATABASE commands */
|
|
|
|
#define GLOBALS_DUMP_FILE "pg_upgrade_dump_globals.sql"
|
2012-12-01 05:30:13 +08:00
|
|
|
#define DB_DUMP_FILE_MASK "pg_upgrade_dump_%u.custom"
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2012-12-27 08:26:30 +08:00
|
|
|
#define DB_DUMP_LOG_FILE_MASK "pg_upgrade_dump_%u.log"
|
2012-03-13 07:47:54 +08:00
|
|
|
#define SERVER_LOG_FILE "pg_upgrade_server.log"
|
|
|
|
#define UTILITY_LOG_FILE "pg_upgrade_utility.log"
|
|
|
|
#define INTERNAL_LOG_FILE "pg_upgrade_internal.log"
|
|
|
|
|
|
|
|
extern char *output_files[];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WIN32 files do not accept writes from multiple processes
|
|
|
|
*
|
|
|
|
* On Win32, we can't send both pg_upgrade output and command output to the
|
|
|
|
* same file because we get the error: "The process cannot access the file
|
|
|
|
* because it is being used by another process." so send the pg_ctl
|
2012-05-24 08:19:21 +08:00
|
|
|
* command-line output to a new file, rather than into the server log file.
|
|
|
|
* Ideally we could use UTILITY_LOG_FILE for this, but some Windows platforms
|
2012-05-25 08:30:39 +08:00
|
|
|
* keep the pg_ctl output file open by the running postmaster, even after
|
|
|
|
* pg_ctl exits.
|
2012-03-13 07:47:54 +08:00
|
|
|
*
|
|
|
|
* We could use the Windows pgwin32_open() flags to allow shared file
|
|
|
|
* writes but is unclear how all other tools would use those flags, so
|
|
|
|
* we just avoid it and log a little differently on Windows; we adjust
|
|
|
|
* the error message appropriately.
|
|
|
|
*/
|
|
|
|
#ifndef WIN32
|
2012-05-25 08:30:39 +08:00
|
|
|
#define SERVER_START_LOG_FILE SERVER_LOG_FILE
|
|
|
|
#define SERVER_STOP_LOG_FILE SERVER_LOG_FILE
|
2012-03-13 07:47:54 +08:00
|
|
|
#else
|
2012-05-25 08:30:39 +08:00
|
|
|
#define SERVER_START_LOG_FILE "pg_upgrade_server_start.log"
|
2012-09-05 12:01:13 +08:00
|
|
|
/*
|
|
|
|
* "pg_ctl start" keeps SERVER_START_LOG_FILE and SERVER_LOG_FILE open
|
|
|
|
* while the server is running, so we use UTILITY_LOG_FILE for "pg_ctl
|
|
|
|
* stop".
|
|
|
|
*/
|
2012-05-25 21:09:51 +08:00
|
|
|
#define SERVER_STOP_LOG_FILE UTILITY_LOG_FILE
|
2012-03-13 07:47:54 +08:00
|
|
|
#endif
|
|
|
|
|
2012-03-17 21:56:47 +08:00
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
#ifndef WIN32
|
|
|
|
#define pg_copy_file copy_file
|
|
|
|
#define pg_mv_file rename
|
|
|
|
#define pg_link_file link
|
2013-05-30 04:58:43 +08:00
|
|
|
#define PATH_SEPARATOR '/'
|
2010-10-19 23:52:43 +08:00
|
|
|
#define RM_CMD "rm -f"
|
2010-05-12 10:19:11 +08:00
|
|
|
#define RMDIR_CMD "rm -rf"
|
2010-10-19 23:57:55 +08:00
|
|
|
#define SCRIPT_EXT "sh"
|
2012-06-11 03:20:04 +08:00
|
|
|
#define ECHO_QUOTE "'"
|
2013-05-30 04:58:43 +08:00
|
|
|
#define ECHO_BLANK ""
|
2010-05-12 10:19:11 +08:00
|
|
|
#else
|
|
|
|
#define pg_copy_file CopyFile
|
|
|
|
#define pg_mv_file pgrename
|
|
|
|
#define pg_link_file win32_pghardlink
|
|
|
|
#define sleep(x) Sleep(x * 1000)
|
2013-05-30 04:58:43 +08:00
|
|
|
#define PATH_SEPARATOR '\\'
|
2010-10-19 23:52:43 +08:00
|
|
|
#define RM_CMD "DEL /q"
|
2010-05-12 10:19:11 +08:00
|
|
|
#define RMDIR_CMD "RMDIR /s/q"
|
2010-10-19 23:57:55 +08:00
|
|
|
#define SCRIPT_EXT "bat"
|
2010-07-01 23:52:52 +08:00
|
|
|
#define EXE_EXT ".exe"
|
2012-06-11 03:20:04 +08:00
|
|
|
#define ECHO_QUOTE ""
|
2013-05-30 04:58:43 +08:00
|
|
|
#define ECHO_BLANK "."
|
2010-05-12 10:19:11 +08:00
|
|
|
#endif
|
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
#define CLUSTER_NAME(cluster) ((cluster) == &old_cluster ? "old" : \
|
|
|
|
(cluster) == &new_cluster ? "new" : "none")
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-09-29 06:11:17 +08:00
|
|
|
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
/* OID system catalog preservation added during PG 9.0 development */
|
2011-04-26 00:00:21 +08:00
|
|
|
#define TABLE_SPACE_SUBDIRS_CAT_VER 201001111
|
|
|
|
/* postmaster/postgres -b (binary_upgrade) flag added during PG 9.1 development */
|
|
|
|
#define BINARY_UPGRADE_SERVER_FLAG_CAT_VER 201104251
|
2011-08-19 23:20:30 +08:00
|
|
|
/*
|
2012-06-11 03:20:04 +08:00
|
|
|
* Visibility map changed with this 9.2 commit,
|
2011-08-19 23:20:30 +08:00
|
|
|
* 8f9fe6edce358f7904e0db119416b4d1080a83aa; pick later catalog version.
|
|
|
|
*/
|
|
|
|
#define VISIBILITY_MAP_CRASHSAFE_CAT_VER 201107031
|
|
|
|
|
Improve concurrency of foreign key locking
This patch introduces two additional lock modes for tuples: "SELECT FOR
KEY SHARE" and "SELECT FOR NO KEY UPDATE". These don't block each
other, in contrast with already existing "SELECT FOR SHARE" and "SELECT
FOR UPDATE". UPDATE commands that do not modify the values stored in
the columns that are part of the key of the tuple now grab a SELECT FOR
NO KEY UPDATE lock on the tuple, allowing them to proceed concurrently
with tuple locks of the FOR KEY SHARE variety.
Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; this
means the concurrency improvement applies to them, which is the whole
point of this patch.
The added tuple lock semantics require some rejiggering of the multixact
module, so that the locking level that each transaction is holding can
be stored alongside its Xid. Also, multixacts now need to persist
across server restarts and crashes, because they can now represent not
only tuple locks, but also tuple updates. This means we need more
careful tracking of lifetime of pg_multixact SLRU files; since they now
persist longer, we require more infrastructure to figure out when they
can be removed. pg_upgrade also needs to be careful to copy
pg_multixact files over from the old server to the new, or at least part
of multixact.c state, depending on the versions of the old and new
servers.
Tuple time qualification rules (HeapTupleSatisfies routines) need to be
careful not to consider tuples with the "is multi" infomask bit set as
being only locked; they might need to look up MultiXact values (i.e.
possibly do pg_multixact I/O) to find out the Xid that updated a tuple,
whereas they previously were assured to only use information readily
available from the tuple header. This is considered acceptable, because
the extra I/O would involve cases that would previously cause some
commands to block waiting for concurrent transactions to finish.
Another important change is the fact that locking tuples that have
previously been updated causes the future versions to be marked as
locked, too; this is essential for correctness of foreign key checks.
This causes additional WAL-logging, also (there was previously a single
WAL record for a locked tuple; now there are as many as updated copies
of the tuple there exist.)
With all this in place, contention related to tuples being checked by
foreign key rules should be much reduced.
As a bonus, the old behavior that a subtransaction grabbing a stronger
tuple lock than the parent (sub)transaction held on a given tuple and
later aborting caused the weaker lock to be lost, has been fixed.
Many new spec files were added for isolation tester framework, to ensure
overall behavior is sane. There's probably room for several more tests.
There were several reviewers of this patch; in particular, Noah Misch
and Andres Freund spent considerable time in it. Original idea for the
patch came from Simon Riggs, after a problem report by Joel Jacobson.
Most code is from me, with contributions from Marti Raudsepp, Alexander
Shulgin, Noah Misch and Andres Freund.
This patch was discussed in several pgsql-hackers threads; the most
important start at the following message-ids:
AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com
1290721684-sup-3951@alvh.no-ip.org
1294953201-sup-2099@alvh.no-ip.org
1320343602-sup-2290@alvh.no-ip.org
1339690386-sup-8927@alvh.no-ip.org
4FE5FF020200002500048A3D@gw.wicourts.gov
4FEAB90A0200002500048B7D@gw.wicourts.gov
2013-01-23 23:04:59 +08:00
|
|
|
/*
|
2013-03-01 03:29:17 +08:00
|
|
|
* pg_multixact format changed in 9.3 commit 0ac5ad5134f2769ccbaefec73844f85,
|
|
|
|
* ("Improve concurrency of foreign key locking") which also updated catalog
|
|
|
|
* version to this value. pg_upgrade behavior depends on whether old and new
|
|
|
|
* server versions are both newer than this, or only the new one is.
|
Improve concurrency of foreign key locking
This patch introduces two additional lock modes for tuples: "SELECT FOR
KEY SHARE" and "SELECT FOR NO KEY UPDATE". These don't block each
other, in contrast with already existing "SELECT FOR SHARE" and "SELECT
FOR UPDATE". UPDATE commands that do not modify the values stored in
the columns that are part of the key of the tuple now grab a SELECT FOR
NO KEY UPDATE lock on the tuple, allowing them to proceed concurrently
with tuple locks of the FOR KEY SHARE variety.
Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; this
means the concurrency improvement applies to them, which is the whole
point of this patch.
The added tuple lock semantics require some rejiggering of the multixact
module, so that the locking level that each transaction is holding can
be stored alongside its Xid. Also, multixacts now need to persist
across server restarts and crashes, because they can now represent not
only tuple locks, but also tuple updates. This means we need more
careful tracking of lifetime of pg_multixact SLRU files; since they now
persist longer, we require more infrastructure to figure out when they
can be removed. pg_upgrade also needs to be careful to copy
pg_multixact files over from the old server to the new, or at least part
of multixact.c state, depending on the versions of the old and new
servers.
Tuple time qualification rules (HeapTupleSatisfies routines) need to be
careful not to consider tuples with the "is multi" infomask bit set as
being only locked; they might need to look up MultiXact values (i.e.
possibly do pg_multixact I/O) to find out the Xid that updated a tuple,
whereas they previously were assured to only use information readily
available from the tuple header. This is considered acceptable, because
the extra I/O would involve cases that would previously cause some
commands to block waiting for concurrent transactions to finish.
Another important change is the fact that locking tuples that have
previously been updated causes the future versions to be marked as
locked, too; this is essential for correctness of foreign key checks.
This causes additional WAL-logging, also (there was previously a single
WAL record for a locked tuple; now there are as many as updated copies
of the tuple there exist.)
With all this in place, contention related to tuples being checked by
foreign key rules should be much reduced.
As a bonus, the old behavior that a subtransaction grabbing a stronger
tuple lock than the parent (sub)transaction held on a given tuple and
later aborting caused the weaker lock to be lost, has been fixed.
Many new spec files were added for isolation tester framework, to ensure
overall behavior is sane. There's probably room for several more tests.
There were several reviewers of this patch; in particular, Noah Misch
and Andres Freund spent considerable time in it. Original idea for the
patch came from Simon Riggs, after a problem report by Joel Jacobson.
Most code is from me, with contributions from Marti Raudsepp, Alexander
Shulgin, Noah Misch and Andres Freund.
This patch was discussed in several pgsql-hackers threads; the most
important start at the following message-ids:
AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com
1290721684-sup-3951@alvh.no-ip.org
1294953201-sup-2099@alvh.no-ip.org
1320343602-sup-2290@alvh.no-ip.org
1339690386-sup-8927@alvh.no-ip.org
4FE5FF020200002500048A3D@gw.wicourts.gov
4FEAB90A0200002500048B7D@gw.wicourts.gov
2013-01-23 23:04:59 +08:00
|
|
|
*/
|
|
|
|
#define MULTIXACT_FORMATCHANGE_CAT_VER 201301231
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Each relation is represented by a relinfo structure.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-12-21 02:56:24 +08:00
|
|
|
/* Can't use NAMEDATALEN; not guaranteed to fit on client */
|
2013-05-30 04:58:43 +08:00
|
|
|
char *nspname; /* namespace name */
|
|
|
|
char *relname; /* relation name */
|
2011-01-08 10:25:34 +08:00
|
|
|
Oid reloid; /* relation oid */
|
|
|
|
Oid relfilenode; /* relation relfile node */
|
2012-04-11 07:57:14 +08:00
|
|
|
/* relation tablespace path, or "" for the cluster default */
|
2012-06-11 03:20:04 +08:00
|
|
|
char tablespace[MAXPGPATH];
|
2010-05-12 10:19:11 +08:00
|
|
|
} RelInfo;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
RelInfo *rels;
|
|
|
|
int nrels;
|
|
|
|
} RelInfoArr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following structure represents a relation mapping.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2013-01-09 21:57:47 +08:00
|
|
|
char old_tablespace[MAXPGPATH];
|
|
|
|
char new_tablespace[MAXPGPATH];
|
|
|
|
char old_tablespace_suffix[MAXPGPATH];
|
|
|
|
char new_tablespace_suffix[MAXPGPATH];
|
|
|
|
Oid old_db_oid;
|
|
|
|
Oid new_db_oid;
|
2011-04-10 23:42:00 +08:00
|
|
|
|
2011-01-06 00:37:08 +08:00
|
|
|
/*
|
|
|
|
* old/new relfilenodes might differ for pg_largeobject(_metadata) indexes
|
|
|
|
* due to VACUUM FULL or REINDEX. Other relfilenodes are preserved.
|
|
|
|
*/
|
|
|
|
Oid old_relfilenode;
|
|
|
|
Oid new_relfilenode;
|
|
|
|
/* the rest are used only for logging and error reporting */
|
2013-05-30 04:58:43 +08:00
|
|
|
char *nspname; /* namespaces */
|
|
|
|
char *relname;
|
2010-05-12 10:19:11 +08:00
|
|
|
} FileNameMap;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structure to store database information
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Oid db_oid; /* oid of the database */
|
2013-05-30 04:58:43 +08:00
|
|
|
char *db_name; /* database name */
|
2010-05-12 10:19:11 +08:00
|
|
|
char db_tblspace[MAXPGPATH]; /* database default tablespace path */
|
|
|
|
RelInfoArr rel_arr; /* array of all user relinfos */
|
|
|
|
} DbInfo;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
DbInfo *dbs; /* array of db infos */
|
|
|
|
int ndbs; /* number of db infos */
|
|
|
|
} DbInfoArr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following structure is used to hold pg_control information.
|
|
|
|
* Rather than using the backend's control structure we use our own
|
|
|
|
* structure to avoid pg_control version issues between releases.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint32 ctrl_ver;
|
|
|
|
uint32 cat_ver;
|
2012-06-26 12:35:57 +08:00
|
|
|
char nextxlogfile[25];
|
2010-05-12 10:19:11 +08:00
|
|
|
uint32 chkpnt_tli;
|
|
|
|
uint32 chkpnt_nxtxid;
|
|
|
|
uint32 chkpnt_nxtoid;
|
Improve concurrency of foreign key locking
This patch introduces two additional lock modes for tuples: "SELECT FOR
KEY SHARE" and "SELECT FOR NO KEY UPDATE". These don't block each
other, in contrast with already existing "SELECT FOR SHARE" and "SELECT
FOR UPDATE". UPDATE commands that do not modify the values stored in
the columns that are part of the key of the tuple now grab a SELECT FOR
NO KEY UPDATE lock on the tuple, allowing them to proceed concurrently
with tuple locks of the FOR KEY SHARE variety.
Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; this
means the concurrency improvement applies to them, which is the whole
point of this patch.
The added tuple lock semantics require some rejiggering of the multixact
module, so that the locking level that each transaction is holding can
be stored alongside its Xid. Also, multixacts now need to persist
across server restarts and crashes, because they can now represent not
only tuple locks, but also tuple updates. This means we need more
careful tracking of lifetime of pg_multixact SLRU files; since they now
persist longer, we require more infrastructure to figure out when they
can be removed. pg_upgrade also needs to be careful to copy
pg_multixact files over from the old server to the new, or at least part
of multixact.c state, depending on the versions of the old and new
servers.
Tuple time qualification rules (HeapTupleSatisfies routines) need to be
careful not to consider tuples with the "is multi" infomask bit set as
being only locked; they might need to look up MultiXact values (i.e.
possibly do pg_multixact I/O) to find out the Xid that updated a tuple,
whereas they previously were assured to only use information readily
available from the tuple header. This is considered acceptable, because
the extra I/O would involve cases that would previously cause some
commands to block waiting for concurrent transactions to finish.
Another important change is the fact that locking tuples that have
previously been updated causes the future versions to be marked as
locked, too; this is essential for correctness of foreign key checks.
This causes additional WAL-logging, also (there was previously a single
WAL record for a locked tuple; now there are as many as updated copies
of the tuple there exist.)
With all this in place, contention related to tuples being checked by
foreign key rules should be much reduced.
As a bonus, the old behavior that a subtransaction grabbing a stronger
tuple lock than the parent (sub)transaction held on a given tuple and
later aborting caused the weaker lock to be lost, has been fixed.
Many new spec files were added for isolation tester framework, to ensure
overall behavior is sane. There's probably room for several more tests.
There were several reviewers of this patch; in particular, Noah Misch
and Andres Freund spent considerable time in it. Original idea for the
patch came from Simon Riggs, after a problem report by Joel Jacobson.
Most code is from me, with contributions from Marti Raudsepp, Alexander
Shulgin, Noah Misch and Andres Freund.
This patch was discussed in several pgsql-hackers threads; the most
important start at the following message-ids:
AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com
1290721684-sup-3951@alvh.no-ip.org
1294953201-sup-2099@alvh.no-ip.org
1320343602-sup-2290@alvh.no-ip.org
1339690386-sup-8927@alvh.no-ip.org
4FE5FF020200002500048A3D@gw.wicourts.gov
4FEAB90A0200002500048B7D@gw.wicourts.gov
2013-01-23 23:04:59 +08:00
|
|
|
uint32 chkpnt_nxtmulti;
|
|
|
|
uint32 chkpnt_nxtmxoff;
|
|
|
|
uint32 chkpnt_oldstMulti;
|
2010-05-12 10:19:11 +08:00
|
|
|
uint32 align;
|
|
|
|
uint32 blocksz;
|
|
|
|
uint32 largesz;
|
|
|
|
uint32 walsz;
|
|
|
|
uint32 walseg;
|
|
|
|
uint32 ident;
|
|
|
|
uint32 index;
|
|
|
|
uint32 toast;
|
|
|
|
bool date_is_int;
|
|
|
|
bool float8_pass_by_value;
|
2013-04-30 22:49:24 +08:00
|
|
|
bool data_checksum_version;
|
2010-05-12 10:19:11 +08:00
|
|
|
char *lc_collate;
|
|
|
|
char *lc_ctype;
|
|
|
|
char *encoding;
|
|
|
|
} ControlData;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enumeration to denote link modes
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
TRANSFER_MODE_COPY,
|
|
|
|
TRANSFER_MODE_LINK
|
|
|
|
} transferMode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enumeration to denote pg_log modes
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
2012-03-13 07:47:54 +08:00
|
|
|
PG_VERBOSE,
|
2012-12-08 01:26:13 +08:00
|
|
|
PG_STATUS,
|
2010-05-12 10:19:11 +08:00
|
|
|
PG_REPORT,
|
|
|
|
PG_WARNING,
|
2012-03-13 07:47:54 +08:00
|
|
|
PG_FATAL
|
2010-05-12 10:19:11 +08:00
|
|
|
} eLogType;
|
|
|
|
|
|
|
|
|
|
|
|
typedef long pgpid_t;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cluster
|
|
|
|
*
|
|
|
|
* information about each cluster
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ControlData controldata; /* pg_control information */
|
2010-07-07 03:19:02 +08:00
|
|
|
DbInfoArr dbarr; /* dbinfos array */
|
|
|
|
char *pgdata; /* pathname for cluster's $PGDATA directory */
|
2012-06-11 03:20:04 +08:00
|
|
|
char *pgconfig; /* pathname for cluster's config file
|
|
|
|
* directory */
|
2010-07-07 03:19:02 +08:00
|
|
|
char *bindir; /* pathname for cluster's executable directory */
|
2012-06-11 03:20:04 +08:00
|
|
|
char *pgopts; /* options to pass to the server, like pg_ctl
|
|
|
|
* -o */
|
2012-09-04 01:52:34 +08:00
|
|
|
char *sockdir; /* directory for Unix Domain socket, if any */
|
2010-07-07 03:19:02 +08:00
|
|
|
unsigned short port; /* port number where postmaster is waiting */
|
|
|
|
uint32 major_version; /* PG_VERSION of cluster */
|
2011-04-10 23:42:00 +08:00
|
|
|
char major_version_str[64]; /* string PG_VERSION of cluster */
|
2011-06-23 08:48:34 +08:00
|
|
|
uint32 bin_version; /* version returned from pg_ctl */
|
2010-07-07 03:19:02 +08:00
|
|
|
Oid pg_database_oid; /* OID of pg_database relation */
|
2013-05-30 04:58:43 +08:00
|
|
|
Oid install_role_oid; /* OID of connected role */
|
|
|
|
Oid role_count; /* number of roles defined in the cluster */
|
2010-07-07 03:19:02 +08:00
|
|
|
char *tablespace_suffix; /* directory specification */
|
2010-05-12 10:19:11 +08:00
|
|
|
} ClusterInfo;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2010-10-20 10:31:17 +08:00
|
|
|
* LogOpts
|
2010-10-20 05:38:16 +08:00
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-03-13 07:47:54 +08:00
|
|
|
FILE *internal; /* internal log FILE */
|
2010-10-20 05:38:16 +08:00
|
|
|
bool verbose; /* TRUE -> be verbose in messages */
|
2012-03-13 07:47:54 +08:00
|
|
|
bool retain; /* retain log files on success */
|
2010-10-20 10:31:17 +08:00
|
|
|
} LogOpts;
|
2010-10-20 05:38:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* UserOpts
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
bool check; /* TRUE -> ask user for permission to make
|
|
|
|
* changes */
|
|
|
|
transferMode transfer_mode; /* copy files or link them? */
|
2012-12-27 08:26:30 +08:00
|
|
|
int jobs;
|
2010-10-20 05:38:16 +08:00
|
|
|
} UserOpts;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OSInfo
|
2010-05-12 10:19:11 +08:00
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char *progname; /* complete pathname for this program */
|
|
|
|
char *exec_path; /* full path to my executable */
|
|
|
|
char *user; /* username for clusters */
|
2013-06-29 07:11:51 +08:00
|
|
|
bool user_specified; /* user specified on command-line */
|
2013-01-09 21:57:47 +08:00
|
|
|
char **old_tablespaces; /* tablespaces */
|
|
|
|
int num_old_tablespaces;
|
2010-05-12 10:19:11 +08:00
|
|
|
char **libraries; /* loadable libraries */
|
|
|
|
int num_libraries;
|
2011-01-02 01:06:36 +08:00
|
|
|
ClusterInfo *running_cluster;
|
2010-10-20 05:38:16 +08:00
|
|
|
} OSInfo;
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
2011-04-10 23:42:00 +08:00
|
|
|
extern LogOpts log_opts;
|
2010-10-20 06:37:04 +08:00
|
|
|
extern UserOpts user_opts;
|
2011-04-10 23:42:00 +08:00
|
|
|
extern ClusterInfo old_cluster,
|
|
|
|
new_cluster;
|
2010-10-20 06:37:04 +08:00
|
|
|
extern OSInfo os_info;
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* check.c */
|
|
|
|
|
2013-01-25 04:20:11 +08:00
|
|
|
void output_check_banner(bool live_check);
|
2013-05-30 04:58:43 +08:00
|
|
|
void check_and_dump_old_cluster(bool live_check,
|
|
|
|
char **sequence_script_file_name);
|
2010-10-20 05:38:16 +08:00
|
|
|
void check_new_cluster(void);
|
|
|
|
void report_clusters_compatible(void);
|
2011-04-10 23:42:00 +08:00
|
|
|
void issue_warnings(char *sequence_script_file_name);
|
2013-05-30 04:58:43 +08:00
|
|
|
void output_completion_banner(char *analyze_script_file_name,
|
2012-06-11 03:20:04 +08:00
|
|
|
char *deletion_script_file_name);
|
2010-10-20 05:38:16 +08:00
|
|
|
void check_cluster_versions(void);
|
|
|
|
void check_cluster_compatibility(bool live_check);
|
2010-10-20 06:37:04 +08:00
|
|
|
void create_script_for_old_cluster_deletion(char **deletion_script_file_name);
|
2012-03-17 06:54:11 +08:00
|
|
|
void create_script_for_cluster_analyze(char **analyze_script_file_name);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* controldata.c */
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
void get_control_data(ClusterInfo *cluster, bool live_check);
|
2012-03-06 10:19:54 +08:00
|
|
|
void check_control_data(ControlData *oldctrl, ControlData *newctrl);
|
|
|
|
void disable_old_cluster(void);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* dump.c */
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
void generate_old_dump(void);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* exec.c */
|
|
|
|
|
2012-08-28 02:21:09 +08:00
|
|
|
#define EXEC_PSQL_ARGS "--echo-queries --set ON_ERROR_STOP=on --no-psqlrc --dbname=template1"
|
|
|
|
bool
|
|
|
|
exec_prog(const char *log_file, const char *opt_log_file,
|
|
|
|
bool throw_error, const char *fmt,...)
|
|
|
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 4, 5)));
|
2010-10-20 05:38:16 +08:00
|
|
|
void verify_directories(void);
|
2013-01-25 04:20:11 +08:00
|
|
|
bool pid_lock_file_exists(const char *datadir);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* file.c */
|
|
|
|
|
|
|
|
#ifdef PAGE_CONVERSION
|
|
|
|
typedef const char *(*pluginStartup) (uint16 migratorVersion,
|
|
|
|
uint16 *pluginVersion, uint16 newPageVersion,
|
|
|
|
uint16 oldPageVersion, void **pluginData);
|
|
|
|
typedef const char *(*pluginConvertFile) (void *pluginData,
|
|
|
|
const char *dstName, const char *srcName);
|
|
|
|
typedef const char *(*pluginConvertPage) (void *pluginData,
|
|
|
|
const char *dstPage, const char *srcPage);
|
|
|
|
typedef const char *(*pluginShutdown) (void *pluginData);
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2010-07-07 03:19:02 +08:00
|
|
|
uint16 oldPageVersion; /* Page layout version of the old cluster */
|
|
|
|
uint16 newPageVersion; /* Page layout version of the new cluster */
|
2010-05-12 10:19:11 +08:00
|
|
|
uint16 pluginVersion; /* API version of converter plugin */
|
2010-07-07 03:19:02 +08:00
|
|
|
void *pluginData; /* Plugin data (set by plugin) */
|
|
|
|
pluginStartup startup; /* Pointer to plugin's startup function */
|
|
|
|
pluginConvertFile convertFile; /* Pointer to plugin's file converter
|
2010-05-12 10:19:11 +08:00
|
|
|
* function */
|
2010-07-07 03:19:02 +08:00
|
|
|
pluginConvertPage convertPage; /* Pointer to plugin's page converter
|
2010-05-12 10:19:11 +08:00
|
|
|
* function */
|
|
|
|
pluginShutdown shutdown; /* Pointer to plugin's shutdown function */
|
|
|
|
} pageCnvCtx;
|
|
|
|
|
2013-01-03 10:20:13 +08:00
|
|
|
const pageCnvCtx *setupPageConverter(void);
|
2010-05-12 10:19:11 +08:00
|
|
|
#else
|
|
|
|
/* dummy */
|
|
|
|
typedef void *pageCnvCtx;
|
|
|
|
#endif
|
|
|
|
|
2010-10-20 08:33:19 +08:00
|
|
|
const char *copyAndUpdateFile(pageCnvCtx *pageConverter, const char *src,
|
2010-05-12 10:19:11 +08:00
|
|
|
const char *dst, bool force);
|
2010-10-20 08:33:19 +08:00
|
|
|
const char *linkAndUpdateFile(pageCnvCtx *pageConverter, const char *src,
|
2011-04-10 23:42:00 +08:00
|
|
|
const char *dst);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
void check_hard_link(void);
|
2012-06-11 03:20:04 +08:00
|
|
|
FILE *fopen_priv(const char *path, const char *mode);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* function.c */
|
|
|
|
|
2011-01-09 02:44:44 +08:00
|
|
|
void install_support_functions_in_new_db(const char *db_name);
|
|
|
|
void uninstall_support_functions_from_new_cluster(void);
|
2010-10-20 05:38:16 +08:00
|
|
|
void get_loadable_libraries(void);
|
|
|
|
void check_loadable_libraries(void);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* info.c */
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
FileNameMap *gen_db_file_maps(DbInfo *old_db,
|
2010-07-07 03:19:02 +08:00
|
|
|
DbInfo *new_db, int *nmaps, const char *old_pgdata,
|
|
|
|
const char *new_pgdata);
|
2011-04-10 23:42:00 +08:00
|
|
|
void get_db_and_rel_infos(ClusterInfo *cluster);
|
|
|
|
void print_maps(FileNameMap *maps, int n,
|
|
|
|
const char *db_name);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* option.c */
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
void parseCommandLine(int argc, char *argv[]);
|
2011-10-08 02:40:23 +08:00
|
|
|
void adjust_data_dir(ClusterInfo *cluster);
|
2012-09-04 01:52:34 +08:00
|
|
|
void get_sock_dir(ClusterInfo *cluster, bool live_check);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* relfilenode.c */
|
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
void get_pg_database_relfilenode(ClusterInfo *cluster);
|
2013-05-30 04:58:43 +08:00
|
|
|
void transfer_all_new_tablespaces(DbInfoArr *old_db_arr,
|
|
|
|
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata);
|
|
|
|
void transfer_all_new_dbs(DbInfoArr *old_db_arr,
|
2013-01-09 21:57:47 +08:00
|
|
|
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata,
|
2013-05-30 04:58:43 +08:00
|
|
|
char *old_tablespace);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* tablespace.c */
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
void init_tablespaces(void);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* server.c */
|
|
|
|
|
2011-04-10 23:42:00 +08:00
|
|
|
PGconn *connectToServer(ClusterInfo *cluster, const char *db_name);
|
2012-06-11 03:20:04 +08:00
|
|
|
PGresult *
|
|
|
|
executeQueryOrDie(PGconn *conn, const char *fmt,...)
|
|
|
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2012-09-04 01:52:34 +08:00
|
|
|
char *cluster_conn_opts(ClusterInfo *cluster);
|
|
|
|
|
2013-01-25 04:20:11 +08:00
|
|
|
bool start_postmaster(ClusterInfo *cluster, bool throw_error);
|
2011-04-26 08:17:48 +08:00
|
|
|
void stop_postmaster(bool fast);
|
2011-04-10 23:42:00 +08:00
|
|
|
uint32 get_major_server_version(ClusterInfo *cluster);
|
2011-05-16 22:46:52 +08:00
|
|
|
void check_pghost_envvar(void);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* util.c */
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
char *quote_identifier(const char *s);
|
|
|
|
int get_user_info(char **user_name);
|
|
|
|
void check_ok(void);
|
2012-06-11 03:20:04 +08:00
|
|
|
void
|
|
|
|
report_status(eLogType type, const char *fmt,...)
|
|
|
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
|
|
|
void
|
|
|
|
pg_log(eLogType type, char *fmt,...)
|
|
|
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
2012-12-01 05:30:13 +08:00
|
|
|
void end_progress_output(void);
|
2012-06-11 03:20:04 +08:00
|
|
|
void
|
|
|
|
prep_status(const char *fmt,...)
|
|
|
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
|
2010-10-20 05:38:16 +08:00
|
|
|
void check_ok(void);
|
2010-05-12 10:19:11 +08:00
|
|
|
const char *getErrorText(int errNum);
|
2010-09-29 05:41:03 +08:00
|
|
|
unsigned int str2uint(const char *str);
|
2011-06-10 02:32:50 +08:00
|
|
|
void pg_putenv(const char *var, const char *val);
|
2010-09-29 05:41:03 +08:00
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* version.c */
|
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
void new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster,
|
2011-04-10 23:42:00 +08:00
|
|
|
bool check_mode);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* version_old_8_3.c */
|
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
void old_8_3_check_for_name_data_type_usage(ClusterInfo *cluster);
|
|
|
|
void old_8_3_check_for_tsquery_usage(ClusterInfo *cluster);
|
2011-09-08 02:42:34 +08:00
|
|
|
void old_8_3_check_ltree_usage(ClusterInfo *cluster);
|
2011-04-10 23:42:00 +08:00
|
|
|
void old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode);
|
|
|
|
void old_8_3_invalidate_hash_gin_indexes(ClusterInfo *cluster, bool check_mode);
|
2011-01-02 01:06:36 +08:00
|
|
|
void old_8_3_invalidate_bpchar_pattern_ops_indexes(ClusterInfo *cluster,
|
2011-04-10 23:42:00 +08:00
|
|
|
bool check_mode);
|
2011-01-02 01:06:36 +08:00
|
|
|
char *old_8_3_create_sequence_script(ClusterInfo *cluster);
|
2012-12-27 08:26:30 +08:00
|
|
|
|
|
|
|
/* parallel.c */
|
2013-05-30 04:58:43 +08:00
|
|
|
void
|
|
|
|
parallel_exec_prog(const char *log_file, const char *opt_log_file,
|
|
|
|
const char *fmt,...)
|
2012-12-27 08:26:30 +08:00
|
|
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
|
2013-05-30 04:58:43 +08:00
|
|
|
void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
|
|
|
|
char *old_pgdata, char *new_pgdata,
|
|
|
|
char *old_tablespace);
|
2013-01-09 21:57:47 +08:00
|
|
|
bool reap_child(bool wait_for_child);
|