Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

tablespace.c File Reference

#include "postgres_fe.h"
#include "pg_upgrade.h"
Include dependency graph for tablespace.c:

Go to the source code of this file.

Functions

static void get_tablespace_paths (void)
static void set_tablespace_directory_suffix (ClusterInfo *cluster)
void init_tablespaces (void)

Function Documentation

static void get_tablespace_paths ( void   )  [static]

Definition at line 41 of file tablespace.c.

References conn, connectToServer(), executeQueryOrDie(), GET_MAJOR_VERSION, ClusterInfo::major_version, OSInfo::num_old_tablespaces, old_cluster, OSInfo::old_tablespaces, os_info, pg_malloc(), pg_strdup(), PQclear(), PQfinish(), PQfnumber(), PQgetvalue(), PQntuples(), and snprintf().

Referenced by init_tablespaces().

{
    PGconn     *conn = connectToServer(&old_cluster, "template1");
    PGresult   *res;
    int         tblnum;
    int         i_spclocation;
    char        query[QUERY_ALLOC];

    snprintf(query, sizeof(query),
             "SELECT    %s "
             "FROM  pg_catalog.pg_tablespace "
             "WHERE spcname != 'pg_default' AND "
             "      spcname != 'pg_global'",
    /* 9.2 removed the spclocation column */
             (GET_MAJOR_VERSION(old_cluster.major_version) <= 901) ?
    "spclocation" : "pg_catalog.pg_tablespace_location(oid) AS spclocation");

    res = executeQueryOrDie(conn, "%s", query);

    if ((os_info.num_old_tablespaces = PQntuples(res)) != 0)
        os_info.old_tablespaces = (char **) pg_malloc(
                                   os_info.num_old_tablespaces * sizeof(char *));
    else
        os_info.old_tablespaces = NULL;

    i_spclocation = PQfnumber(res, "spclocation");

    for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
        os_info.old_tablespaces[tblnum] = pg_strdup(
                                     PQgetvalue(res, tblnum, i_spclocation));

    PQclear(res);

    PQfinish(conn);

    return;
}

void init_tablespaces ( void   ) 
static void set_tablespace_directory_suffix ( ClusterInfo cluster  )  [static]

Definition at line 81 of file tablespace.c.

References ControlData::cat_ver, ClusterInfo::controldata, GET_MAJOR_VERSION, ClusterInfo::major_version, ClusterInfo::major_version_str, pg_malloc(), pg_strdup(), and ClusterInfo::tablespace_suffix.

Referenced by init_tablespaces().

{
    if (GET_MAJOR_VERSION(cluster->major_version) <= 804)
        cluster->tablespace_suffix = pg_strdup("");
    else
    {
        /* This cluster has a version-specific subdirectory */
        cluster->tablespace_suffix = pg_malloc(4 +
                                         strlen(cluster->major_version_str) +
                                               10 /* OIDCHARS */ + 1);

        /* The leading slash is needed to start a new directory. */
        sprintf(cluster->tablespace_suffix, "/PG_%s_%d", cluster->major_version_str,
                cluster->controldata.cat_ver);
    }
}