Header And Logo

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

Functions

version.c File Reference

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

Go to the source code of this file.

Functions

void new_9_0_populate_pg_largeobject_metadata (ClusterInfo *cluster, bool check_mode)

Function Documentation

void new_9_0_populate_pg_largeobject_metadata ( ClusterInfo cluster,
bool  check_mode 
)

Definition at line 22 of file version.c.

References check_ok(), conn, connectToServer(), DbInfo::db_name, ClusterInfo::dbarr, DbInfoArr::dbs, executeQueryOrDie(), fopen_priv(), getErrorText(), DbInfoArr::ndbs, NULL, PG_FATAL, pg_log(), PG_WARNING, PQclear(), PQfinish(), PQfnumber(), PQgetvalue(), prep_status(), quote_identifier(), report_status(), and snprintf().

Referenced by check_and_dump_old_cluster(), and issue_warnings().

{
    int         dbnum;
    FILE       *script = NULL;
    bool        found = false;
    char        output_path[MAXPGPATH];

    prep_status("Checking for large objects");

    snprintf(output_path, sizeof(output_path), "pg_largeobject.sql");

    for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
    {
        PGresult   *res;
        int         i_count;
        DbInfo     *active_db = &cluster->dbarr.dbs[dbnum];
        PGconn     *conn = connectToServer(cluster, active_db->db_name);

        /* find if there are any large objects */
        res = executeQueryOrDie(conn,
                                "SELECT count(*) "
                                "FROM   pg_catalog.pg_largeobject ");

        i_count = PQfnumber(res, "count");
        if (atoi(PQgetvalue(res, 0, i_count)) != 0)
        {
            found = true;
            if (!check_mode)
            {
                if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
                    pg_log(PG_FATAL, "could not open file \"%s\": %s\n", output_path, getErrorText(errno));
                fprintf(script, "\\connect %s\n",
                        quote_identifier(active_db->db_name));
                fprintf(script,
                        "SELECT pg_catalog.lo_create(t.loid)\n"
                        "FROM (SELECT DISTINCT loid FROM pg_catalog.pg_largeobject) AS t;\n");
            }
        }

        PQclear(res);
        PQfinish(conn);
    }

    if (script)
        fclose(script);

    if (found)
    {
        report_status(PG_WARNING, "warning");
        if (check_mode)
            pg_log(PG_WARNING, "\n"
                   "Your installation contains large objects.  The new database has an\n"
                   "additional large object permission table.  After upgrading, you will be\n"
                   "given a command to populate the pg_largeobject permission table with\n"
                   "default permissions.\n\n");
        else
            pg_log(PG_WARNING, "\n"
                   "Your installation contains large objects.  The new database has an\n"
                   "additional large object permission table, so default permissions must be\n"
                   "defined for all large objects.  The file\n"
                   "    %s\n"
                   "when executed by psql by the database superuser will set the default\n"
                   "permissions.\n\n",
                   output_path);
    }
    else
        check_ok();
}