Skip to content

Commit

Permalink
Merge pull request IvorySQL#621 from jiaoshuntian/master
Browse files Browse the repository at this point in the history
IvorySQL: fix issue#575
  • Loading branch information
gaoxueyu authored Jan 23, 2024
2 parents a8b99b9 + 4a39c0b commit 7845882
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/bin/initdb/initdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ static void load_ivorysql_ora(FILE *cmdfd);
static void vacuum_db(FILE *cmdfd);
static void make_template0(FILE *cmdfd);
static void make_postgres(FILE *cmdfd);
static void make_ivorysql(FILE *cmdfd);
static void trapsig(SIGNAL_ARGS);
static void check_ok(void);
static char *escape_quotes(const char *src);
Expand Down Expand Up @@ -2101,6 +2102,16 @@ make_postgres(FILE *cmdfd)
PG_CMD_PUTS("COMMENT ON DATABASE postgres IS 'default administrative connection database';\n\n");
}

/*
* copy template1 to ivorysql
*/
static void
make_ivorysql(FILE *cmdfd)
{
PG_CMD_PUTS("CREATE DATABASE ivorysql;\n\n");
PG_CMD_PUTS("COMMENT ON DATABASE ivorysql IS 'default administrative connection database';\n\n");
}

/*
* signal handler in case we are interrupted.
*
Expand Down Expand Up @@ -3192,6 +3203,8 @@ initialize_data_directory(void)
make_template0(cmdfd);

make_postgres(cmdfd);

make_ivorysql(cmdfd);

PG_CMD_CLOSE;

Expand Down
9 changes: 6 additions & 3 deletions src/bin/pg_dump/pg_dumpall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1361,12 +1361,13 @@ dropDBs(PGconn *conn)
char *dbname = PQgetvalue(res, i, 0);

/*
* Skip "postgres" and "template1"; dumpDatabases() will deal with
* Skip "postgres", "ivorysql", and "template1"; dumpDatabases() will deal with
* them specially. Also, be sure to skip "template0", even if for
* some reason it's not marked !datallowconn.
*/
if (strcmp(dbname, "template1") != 0 &&
strcmp(dbname, "template0") != 0 &&
strcmp(dbname, "ivorysql") != 0 &&
strcmp(dbname, "postgres") != 0)
{
fprintf(OPF, "DROP DATABASE %s%s;\n",
Expand Down Expand Up @@ -1521,14 +1522,16 @@ dumpDatabases(PGconn *conn)
fprintf(OPF, "--\n-- Database \"%s\" dump\n--\n\n", dbname);

/*
* We assume that "template1" and "postgres" already exist in the
* We assume that "template1", "postgres", and "ivorysql" already exist in the
* target installation. dropDBs() won't have removed them, for fear
* of removing the DB the restore script is initially connected to. If
* --clean was specified, tell pg_dump to drop and recreate them;
* otherwise we'll merely restore their contents. Other databases
* should simply be created.
*/
if (strcmp(dbname, "template1") == 0 || strcmp(dbname, "postgres") == 0)
if (strcmp(dbname, "template1") == 0 ||
strcmp(dbname, "postgres") == 0 ||
strcmp(dbname, "ivorysql") == 0)
{
if (output_clean)
create_opts = "--clean --create";
Expand Down
1 change: 1 addition & 0 deletions src/bin/pg_rewind/t/002_databases.pl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ sub run_test
'SELECT datname FROM pg_database ORDER BY 1',
qq(beforepromotion
inprimary
ivorysql
postgres
standby_afterpromotion
template0
Expand Down
5 changes: 3 additions & 2 deletions src/bin/pg_upgrade/pg_upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,12 @@ create_new_objects(void)
snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid);

/*
* postgres database will already exist in the target installation, so
* postgres database and ivorysql database will already exist in the target installation, so
* tell pg_restore to drop and recreate it; otherwise we would fail to
* propagate its database-level properties.
*/
if (strcmp(old_db->db_name, "postgres") == 0)
if (strcmp(old_db->db_name, "postgres") == 0 ||
strcmp(old_db->db_name, "ivorysql") == 0)
create_opts = "--clean --create";
else
create_opts = "--create";
Expand Down
2 changes: 1 addition & 1 deletion src/bin/psql/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ main(int argc, char *argv[])
values[3] = password;
keywords[4] = "dbname"; /* see do_connect() */
values[4] = (options.list_dbs && options.dbname == NULL) ?
"postgres" : options.dbname;
"ivorysql" : options.dbname;
keywords[5] = "fallback_application_name";
values[5] = pset.progname;
keywords[6] = "client_encoding";
Expand Down

0 comments on commit 7845882

Please sign in to comment.