2010-05-12 10:19:11 +08:00
|
|
|
/*
|
|
|
|
* info.c
|
|
|
|
*
|
|
|
|
* information support functions
|
2010-07-03 22:23:14 +08:00
|
|
|
*
|
2012-01-02 07:01:58 +08:00
|
|
|
* Copyright (c) 2010-2012, PostgreSQL Global Development Group
|
2010-09-21 04:08:53 +08:00
|
|
|
* contrib/pg_upgrade/info.c
|
2010-05-12 10:19:11 +08:00
|
|
|
*/
|
|
|
|
|
2011-08-27 09:16:24 +08:00
|
|
|
#include "postgres.h"
|
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
#include "pg_upgrade.h"
|
|
|
|
|
|
|
|
#include "access/transam.h"
|
|
|
|
|
|
|
|
|
2011-01-05 08:11:00 +08:00
|
|
|
static void create_rel_filename_map(const char *old_data, const char *new_data,
|
2011-04-10 23:42:00 +08:00
|
|
|
const DbInfo *old_db, const DbInfo *new_db,
|
|
|
|
const RelInfo *old_rel, const RelInfo *new_rel,
|
|
|
|
FileNameMap *map);
|
2011-01-11 00:45:22 +08:00
|
|
|
static void get_db_infos(ClusterInfo *cluster);
|
|
|
|
static void get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo);
|
|
|
|
static void free_rel_infos(RelInfoArr *rel_arr);
|
|
|
|
static void print_db_infos(DbInfoArr *dbinfo);
|
|
|
|
static void print_rel_infos(RelInfoArr *arr);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gen_db_file_maps()
|
|
|
|
*
|
|
|
|
* generates database mappings for "old_db" and "new_db". Returns a malloc'ed
|
|
|
|
* array of mappings. nmaps is a return parameter which refers to the number
|
|
|
|
* mappings.
|
|
|
|
*/
|
|
|
|
FileNameMap *
|
2010-10-20 05:38:16 +08:00
|
|
|
gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
|
2010-05-12 10:19:11 +08:00
|
|
|
int *nmaps, const char *old_pgdata, const char *new_pgdata)
|
|
|
|
{
|
|
|
|
FileNameMap *maps;
|
|
|
|
int relnum;
|
|
|
|
int num_maps = 0;
|
|
|
|
|
2011-01-09 02:44:44 +08:00
|
|
|
if (old_db->rel_arr.nrels != new_db->rel_arr.nrels)
|
|
|
|
pg_log(PG_FATAL, "old and new databases \"%s\" have a different number of relations\n",
|
2011-04-10 23:42:00 +08:00
|
|
|
old_db->db_name);
|
2011-01-09 02:44:44 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
maps = (FileNameMap *) pg_malloc(sizeof(FileNameMap) *
|
2011-01-06 00:37:08 +08:00
|
|
|
old_db->rel_arr.nrels);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2011-01-06 00:37:08 +08:00
|
|
|
for (relnum = 0; relnum < old_db->rel_arr.nrels; relnum++)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-01-06 02:52:44 +08:00
|
|
|
RelInfo *old_rel = &old_db->rel_arr.rels[relnum];
|
2011-02-16 08:01:33 +08:00
|
|
|
RelInfo *new_rel = &new_db->rel_arr.rels[relnum];
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2011-01-09 02:44:44 +08:00
|
|
|
if (old_rel->reloid != new_rel->reloid)
|
2011-07-12 12:13:51 +08:00
|
|
|
pg_log(PG_FATAL, "Mismatch of relation OID in database \"%s\": old OID %d, new OID %d\n",
|
2011-04-10 23:42:00 +08:00
|
|
|
old_db->db_name, old_rel->reloid, new_rel->reloid);
|
2011-03-06 10:12:21 +08:00
|
|
|
|
2011-03-06 11:09:35 +08:00
|
|
|
/*
|
2011-09-29 10:30:44 +08:00
|
|
|
* TOAST table names initially match the heap pg_class oid.
|
|
|
|
* In pre-8.4, TOAST table names change during CLUSTER; in pre-9.0,
|
|
|
|
* TOAST table names change during ALTER TABLE ALTER COLUMN SET TYPE.
|
|
|
|
* In >= 9.0, TOAST relation names always use heap table oids, hence
|
|
|
|
* we cannot check relation names when upgrading from pre-9.0.
|
|
|
|
* Clusters upgraded to 9.0 will get matching TOAST names.
|
2011-03-06 11:09:35 +08:00
|
|
|
*/
|
2011-03-06 19:34:58 +08:00
|
|
|
if (strcmp(old_rel->nspname, new_rel->nspname) != 0 ||
|
2011-09-29 10:30:44 +08:00
|
|
|
((GET_MAJOR_VERSION(old_cluster.major_version) >= 900 ||
|
2011-03-07 10:57:02 +08:00
|
|
|
strcmp(old_rel->nspname, "pg_toast") != 0) &&
|
|
|
|
strcmp(old_rel->relname, new_rel->relname) != 0))
|
2011-07-12 12:13:51 +08:00
|
|
|
pg_log(PG_FATAL, "Mismatch of relation names in database \"%s\": "
|
|
|
|
"old name \"%s.%s\", new name \"%s.%s\"\n",
|
2011-04-10 23:42:00 +08:00
|
|
|
old_db->db_name, old_rel->nspname, old_rel->relname,
|
|
|
|
new_rel->nspname, new_rel->relname);
|
2011-03-06 10:12:21 +08:00
|
|
|
|
2011-01-05 08:11:00 +08:00
|
|
|
create_rel_filename_map(old_pgdata, new_pgdata, old_db, new_db,
|
2011-04-10 23:42:00 +08:00
|
|
|
old_rel, new_rel, maps + num_maps);
|
2010-05-12 10:19:11 +08:00
|
|
|
num_maps++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*nmaps = num_maps;
|
|
|
|
return maps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2011-01-05 08:11:00 +08:00
|
|
|
* create_rel_filename_map()
|
2010-05-12 10:19:11 +08:00
|
|
|
*
|
|
|
|
* fills a file node map structure and returns it in "map".
|
|
|
|
*/
|
|
|
|
static void
|
2011-01-05 08:11:00 +08:00
|
|
|
create_rel_filename_map(const char *old_data, const char *new_data,
|
2011-04-10 23:42:00 +08:00
|
|
|
const DbInfo *old_db, const DbInfo *new_db,
|
|
|
|
const RelInfo *old_rel, const RelInfo *new_rel,
|
|
|
|
FileNameMap *map)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-01-05 08:11:00 +08:00
|
|
|
if (strlen(old_rel->tablespace) == 0)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
/*
|
2011-01-05 08:11:00 +08:00
|
|
|
* relation belongs to the default tablespace, hence relfiles should
|
2010-05-12 10:19:11 +08:00
|
|
|
* exist in the data directories.
|
|
|
|
*/
|
2011-01-05 08:11:00 +08:00
|
|
|
snprintf(map->old_dir, sizeof(map->old_dir), "%s/base/%u", old_data,
|
|
|
|
old_db->db_oid);
|
|
|
|
snprintf(map->new_dir, sizeof(map->new_dir), "%s/base/%u", new_data,
|
|
|
|
new_db->db_oid);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-06 00:37:08 +08:00
|
|
|
/* relation belongs to a tablespace, so use the tablespace location */
|
2011-01-05 08:11:00 +08:00
|
|
|
snprintf(map->old_dir, sizeof(map->old_dir), "%s%s/%u", old_rel->tablespace,
|
2010-10-20 05:38:16 +08:00
|
|
|
old_cluster.tablespace_suffix, old_db->db_oid);
|
2011-01-05 08:11:00 +08:00
|
|
|
snprintf(map->new_dir, sizeof(map->new_dir), "%s%s/%u", new_rel->tablespace,
|
2010-10-20 05:38:16 +08:00
|
|
|
new_cluster.tablespace_suffix, new_db->db_oid);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
2011-01-06 00:37:08 +08:00
|
|
|
|
2011-01-08 11:57:30 +08:00
|
|
|
/*
|
2011-04-10 23:42:00 +08:00
|
|
|
* old_relfilenode might differ from pg_class.oid (and hence
|
|
|
|
* new_relfilenode) because of CLUSTER, REINDEX, or VACUUM FULL.
|
2011-01-08 11:57:30 +08:00
|
|
|
*/
|
2011-01-06 00:37:08 +08:00
|
|
|
map->old_relfilenode = old_rel->relfilenode;
|
2011-01-08 11:57:30 +08:00
|
|
|
|
|
|
|
/* new_relfilenode will match old and new pg_class.oid */
|
2011-01-06 00:37:08 +08:00
|
|
|
map->new_relfilenode = new_rel->relfilenode;
|
|
|
|
|
2011-01-08 11:36:51 +08:00
|
|
|
/* used only for logging and error reporing, old/new are identical */
|
|
|
|
snprintf(map->nspname, sizeof(map->nspname), "%s", old_rel->nspname);
|
|
|
|
snprintf(map->relname, sizeof(map->relname), "%s", old_rel->relname);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-11 00:45:22 +08:00
|
|
|
print_maps(FileNameMap *maps, int n_maps, const char *db_name)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2010-10-20 10:31:17 +08:00
|
|
|
if (log_opts.debug)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
int mapnum;
|
|
|
|
|
2011-07-12 12:13:51 +08:00
|
|
|
pg_log(PG_DEBUG, "mappings for database \"%s\":\n", db_name);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2011-01-11 00:45:22 +08:00
|
|
|
for (mapnum = 0; mapnum < n_maps; mapnum++)
|
2011-01-08 11:36:51 +08:00
|
|
|
pg_log(PG_DEBUG, "%s.%s: %u to %u\n",
|
|
|
|
maps[mapnum].nspname, maps[mapnum].relname,
|
2010-10-20 06:37:04 +08:00
|
|
|
maps[mapnum].old_relfilenode,
|
|
|
|
maps[mapnum].new_relfilenode);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_DEBUG, "\n\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-11 00:45:22 +08:00
|
|
|
/*
|
|
|
|
* get_db_and_rel_infos()
|
|
|
|
*
|
|
|
|
* higher level routine to generate dbinfos for the database running
|
|
|
|
* on the given "port". Assumes that server is already running.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
get_db_and_rel_infos(ClusterInfo *cluster)
|
|
|
|
{
|
|
|
|
int dbnum;
|
|
|
|
|
2011-02-16 08:01:33 +08:00
|
|
|
if (cluster->dbarr.dbs != NULL)
|
|
|
|
free_db_and_rel_infos(&cluster->dbarr);
|
2011-02-16 04:00:07 +08:00
|
|
|
|
2011-01-11 00:45:22 +08:00
|
|
|
get_db_infos(cluster);
|
|
|
|
|
|
|
|
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
|
|
|
|
get_rel_infos(cluster, &cluster->dbarr.dbs[dbnum]);
|
|
|
|
|
|
|
|
if (log_opts.debug)
|
|
|
|
{
|
2011-02-16 08:01:33 +08:00
|
|
|
pg_log(PG_DEBUG, "\n%s databases:\n", CLUSTER_NAME(cluster));
|
2011-01-11 00:45:22 +08:00
|
|
|
print_db_infos(&cluster->dbarr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
/*
|
|
|
|
* get_db_infos()
|
|
|
|
*
|
2011-01-02 01:06:36 +08:00
|
|
|
* Scans pg_database system catalog and populates all user
|
2010-05-12 10:19:11 +08:00
|
|
|
* databases.
|
|
|
|
*/
|
|
|
|
static void
|
2011-01-02 01:06:36 +08:00
|
|
|
get_db_infos(ClusterInfo *cluster)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-01-02 01:06:36 +08:00
|
|
|
PGconn *conn = connectToServer(cluster, "template1");
|
2010-05-12 10:19:11 +08:00
|
|
|
PGresult *res;
|
|
|
|
int ntups;
|
|
|
|
int tupnum;
|
|
|
|
DbInfo *dbinfos;
|
2011-04-10 23:42:00 +08:00
|
|
|
int i_datname,
|
|
|
|
i_oid,
|
|
|
|
i_spclocation;
|
2011-12-07 17:35:00 +08:00
|
|
|
char query[QUERY_ALLOC];
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2011-12-07 17:35:00 +08:00
|
|
|
snprintf(query, sizeof(query),
|
|
|
|
"SELECT d.oid, d.datname, %s "
|
|
|
|
"FROM pg_catalog.pg_database d "
|
|
|
|
" LEFT OUTER JOIN pg_catalog.pg_tablespace t "
|
|
|
|
" ON d.dattablespace = t.oid "
|
|
|
|
"WHERE d.datallowconn = true "
|
2011-01-09 02:44:44 +08:00
|
|
|
/* we don't preserve pg_database.oid so we sort by name */
|
2011-12-07 17:35:00 +08:00
|
|
|
"ORDER BY 2",
|
|
|
|
/* 9.2 removed the spclocation column */
|
2012-01-25 10:51:10 +08:00
|
|
|
(GET_MAJOR_VERSION(cluster->major_version) <= 901) ?
|
2011-12-07 17:35:00 +08:00
|
|
|
"t.spclocation" : "pg_catalog.pg_tablespace_location(t.oid) AS spclocation");
|
|
|
|
|
|
|
|
res = executeQueryOrDie(conn, "%s", query);
|
2010-07-07 03:19:02 +08:00
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
i_oid = PQfnumber(res, "oid");
|
2011-03-06 09:18:31 +08:00
|
|
|
i_datname = PQfnumber(res, "datname");
|
2010-05-12 10:19:11 +08:00
|
|
|
i_spclocation = PQfnumber(res, "spclocation");
|
|
|
|
|
|
|
|
ntups = PQntuples(res);
|
2010-10-20 05:38:16 +08:00
|
|
|
dbinfos = (DbInfo *) pg_malloc(sizeof(DbInfo) * ntups);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
for (tupnum = 0; tupnum < ntups; tupnum++)
|
|
|
|
{
|
2010-09-29 06:11:17 +08:00
|
|
|
dbinfos[tupnum].db_oid = atooid(PQgetvalue(res, tupnum, i_oid));
|
2010-05-12 10:19:11 +08:00
|
|
|
snprintf(dbinfos[tupnum].db_name, sizeof(dbinfos[tupnum].db_name), "%s",
|
|
|
|
PQgetvalue(res, tupnum, i_datname));
|
|
|
|
snprintf(dbinfos[tupnum].db_tblspace, sizeof(dbinfos[tupnum].db_tblspace), "%s",
|
|
|
|
PQgetvalue(res, tupnum, i_spclocation));
|
|
|
|
}
|
|
|
|
PQclear(res);
|
|
|
|
|
|
|
|
PQfinish(conn);
|
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
cluster->dbarr.dbs = dbinfos;
|
|
|
|
cluster->dbarr.ndbs = ntups;
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_rel_infos()
|
|
|
|
*
|
|
|
|
* gets the relinfos for all the user tables of the database refered
|
|
|
|
* by "db".
|
|
|
|
*
|
|
|
|
* NOTE: we assume that relations/entities with oids greater than
|
|
|
|
* FirstNormalObjectId belongs to the user
|
|
|
|
*/
|
|
|
|
static void
|
2011-01-05 08:11:00 +08:00
|
|
|
get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-01-02 01:28:48 +08:00
|
|
|
PGconn *conn = connectToServer(cluster,
|
2011-01-05 08:11:00 +08:00
|
|
|
dbinfo->db_name);
|
2010-05-12 10:19:11 +08:00
|
|
|
PGresult *res;
|
|
|
|
RelInfo *relinfos;
|
|
|
|
int ntups;
|
|
|
|
int relnum;
|
|
|
|
int num_rels = 0;
|
|
|
|
char *nspname = NULL;
|
|
|
|
char *relname = NULL;
|
2011-04-10 23:42:00 +08:00
|
|
|
int i_spclocation,
|
|
|
|
i_nspname,
|
|
|
|
i_relname,
|
|
|
|
i_oid,
|
|
|
|
i_relfilenode;
|
2010-05-12 10:19:11 +08:00
|
|
|
char query[QUERY_ALLOC];
|
|
|
|
|
|
|
|
/*
|
2011-01-08 11:36:51 +08:00
|
|
|
* pg_largeobject contains user data that does not appear in pg_dumpall
|
2011-01-08 10:25:34 +08:00
|
|
|
* --schema-only output, so we have to copy that system table heap and
|
2011-04-10 23:42:00 +08:00
|
|
|
* index. We could grab the pg_largeobject oids from template1, but it is
|
|
|
|
* easy to treat it as a normal table. Order by oid so we can join old/new
|
|
|
|
* structures efficiently.
|
2010-05-12 10:19:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
snprintf(query, sizeof(query),
|
2011-01-11 00:45:22 +08:00
|
|
|
"SELECT c.oid, n.nspname, c.relname, "
|
2011-12-07 17:35:00 +08:00
|
|
|
" c.relfilenode, %s "
|
2011-04-07 18:22:40 +08:00
|
|
|
"FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
|
|
|
|
" ON c.relnamespace = n.oid "
|
|
|
|
" LEFT OUTER JOIN pg_catalog.pg_tablespace t "
|
|
|
|
" ON c.reltablespace = t.oid "
|
|
|
|
"WHERE relkind IN ('r','t', 'i'%s) AND "
|
2011-08-26 12:12:32 +08:00
|
|
|
/* exclude possible orphaned temp tables */
|
|
|
|
" ((n.nspname !~ '^pg_temp_' AND "
|
|
|
|
" n.nspname !~ '^pg_toast_temp_' AND "
|
|
|
|
" n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade') AND "
|
2011-04-07 18:22:40 +08:00
|
|
|
" c.oid >= %u) "
|
|
|
|
" OR (n.nspname = 'pg_catalog' AND "
|
2011-04-10 23:42:00 +08:00
|
|
|
" relname IN ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
|
2011-01-09 02:44:44 +08:00
|
|
|
/* we preserve pg_class.oid so we sort by it to match old/new */
|
|
|
|
"ORDER BY 1;",
|
2011-12-07 17:35:00 +08:00
|
|
|
/* 9.2 removed the spclocation column */
|
2012-01-25 10:51:10 +08:00
|
|
|
(GET_MAJOR_VERSION(cluster->major_version) <= 901) ?
|
2011-12-07 17:35:00 +08:00
|
|
|
"t.spclocation" : "pg_catalog.pg_tablespace_location(t.oid) AS spclocation",
|
2011-04-07 18:22:40 +08:00
|
|
|
/* see the comment at the top of old_8_3_create_sequence_script() */
|
|
|
|
(GET_MAJOR_VERSION(old_cluster.major_version) <= 803) ?
|
|
|
|
"" : ", 'S'",
|
|
|
|
/* this oid allows us to skip system toast tables */
|
2010-05-12 10:19:11 +08:00
|
|
|
FirstNormalObjectId,
|
2011-01-05 12:35:49 +08:00
|
|
|
/* does pg_largeobject_metadata need to be migrated? */
|
|
|
|
(GET_MAJOR_VERSION(old_cluster.major_version) <= 804) ?
|
2011-04-10 23:42:00 +08:00
|
|
|
"" : ", 'pg_largeobject_metadata', 'pg_largeobject_metadata_oid_index'");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2011-09-11 04:12:46 +08:00
|
|
|
res = executeQueryOrDie(conn, "%s", query);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
ntups = PQntuples(res);
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
relinfos = (RelInfo *) pg_malloc(sizeof(RelInfo) * ntups);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
i_oid = PQfnumber(res, "oid");
|
|
|
|
i_nspname = PQfnumber(res, "nspname");
|
|
|
|
i_relname = PQfnumber(res, "relname");
|
|
|
|
i_relfilenode = PQfnumber(res, "relfilenode");
|
|
|
|
i_spclocation = PQfnumber(res, "spclocation");
|
|
|
|
|
|
|
|
for (relnum = 0; relnum < ntups; relnum++)
|
|
|
|
{
|
|
|
|
RelInfo *curr = &relinfos[num_rels++];
|
2010-07-07 03:19:02 +08:00
|
|
|
const char *tblspace;
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-09-29 06:11:17 +08:00
|
|
|
curr->reloid = atooid(PQgetvalue(res, relnum, i_oid));
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
nspname = PQgetvalue(res, relnum, i_nspname);
|
2010-05-14 08:32:21 +08:00
|
|
|
strlcpy(curr->nspname, nspname, sizeof(curr->nspname));
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
relname = PQgetvalue(res, relnum, i_relname);
|
2010-05-14 08:32:21 +08:00
|
|
|
strlcpy(curr->relname, relname, sizeof(curr->relname));
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-09-29 06:11:17 +08:00
|
|
|
curr->relfilenode = atooid(PQgetvalue(res, relnum, i_relfilenode));
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
tblspace = PQgetvalue(res, relnum, i_spclocation);
|
|
|
|
/* if no table tablespace, use the database tablespace */
|
|
|
|
if (strlen(tblspace) == 0)
|
2011-01-05 08:11:00 +08:00
|
|
|
tblspace = dbinfo->db_tblspace;
|
2010-05-14 08:32:21 +08:00
|
|
|
strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
PQclear(res);
|
|
|
|
|
|
|
|
PQfinish(conn);
|
|
|
|
|
2011-01-05 08:11:00 +08:00
|
|
|
dbinfo->rel_arr.rels = relinfos;
|
|
|
|
dbinfo->rel_arr.nrels = num_rels;
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-11 00:45:22 +08:00
|
|
|
free_db_and_rel_infos(DbInfoArr *db_arr)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
int dbnum;
|
|
|
|
|
|
|
|
for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
|
2011-01-11 00:45:22 +08:00
|
|
|
free_rel_infos(&db_arr->dbs[dbnum].rel_arr);
|
|
|
|
pg_free(db_arr->dbs);
|
2011-02-16 08:01:33 +08:00
|
|
|
db_arr->dbs = NULL;
|
2010-05-12 10:19:11 +08:00
|
|
|
db_arr->ndbs = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2011-01-11 00:45:22 +08:00
|
|
|
free_rel_infos(RelInfoArr *rel_arr)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-01-11 00:45:22 +08:00
|
|
|
pg_free(rel_arr->rels);
|
|
|
|
rel_arr->nrels = 0;
|
|
|
|
}
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
2011-01-11 00:45:22 +08:00
|
|
|
static void
|
|
|
|
print_db_infos(DbInfoArr *db_arr)
|
|
|
|
{
|
|
|
|
int dbnum;
|
|
|
|
|
|
|
|
for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-01-11 00:45:22 +08:00
|
|
|
pg_log(PG_DEBUG, "Database: %s\n", db_arr->dbs[dbnum].db_name);
|
|
|
|
print_rel_infos(&db_arr->dbs[dbnum].rel_arr);
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_DEBUG, "\n\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2011-01-11 00:45:22 +08:00
|
|
|
print_rel_infos(RelInfoArr *arr)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
int relnum;
|
|
|
|
|
|
|
|
for (relnum = 0; relnum < arr->nrels; relnum++)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_DEBUG, "relname: %s.%s: reloid: %u reltblspace: %s\n",
|
2010-05-12 10:19:11 +08:00
|
|
|
arr->rels[relnum].nspname, arr->rels[relnum].relname,
|
|
|
|
arr->rels[relnum].reloid, arr->rels[relnum].tablespace);
|
|
|
|
}
|