]> granicus.if.org Git - postgresql/blobdiff - src/bin/pg_dump/pg_restore.c
pg_restore: Make not verbose by default
[postgresql] / src / bin / pg_dump / pg_restore.c
index 497677494bc50f6203ac74d3f068ec027d834cec..9a5b17758f995a9f8f81c3873857d79fc425dc72 100644 (file)
  */
 #include "postgres_fe.h"
 
+#include <ctype.h>
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#endif
+
 #include "getopt_long.h"
 
 #include "dumputils.h"
 #include "parallel.h"
 #include "pg_backup_utils.h"
 
-#include <ctype.h>
-
-#ifdef HAVE_TERMIOS_H
-#include <termios.h>
-#endif
-
-#ifdef ENABLE_NLS
-#include <locale.h>
-#endif
+#include "fe_utils/logging.h"
 
 
 static void usage(const char *progname);
@@ -72,12 +69,14 @@ main(int argc, char **argv)
        char       *inputFileSpec;
        static int      disable_triggers = 0;
        static int      enable_row_security = 0;
-       static int      include_subscriptions = 0;
        static int      if_exists = 0;
        static int      no_data_for_failed_tables = 0;
        static int      outputNoTablespaces = 0;
        static int      use_setsessauth = 0;
+       static int      no_comments = 0;
+       static int      no_publications = 0;
        static int      no_security_labels = 0;
+       static int      no_subscriptions = 0;
        static int      strict_names = 0;
 
        struct option cmdopts[] = {
@@ -117,18 +116,22 @@ main(int argc, char **argv)
                {"disable-triggers", no_argument, &disable_triggers, 1},
                {"enable-row-security", no_argument, &enable_row_security, 1},
                {"if-exists", no_argument, &if_exists, 1},
-               {"include-subscriptions", no_argument, &include_subscriptions, 1},
                {"no-data-for-failed-tables", no_argument, &no_data_for_failed_tables, 1},
                {"no-tablespaces", no_argument, &outputNoTablespaces, 1},
                {"role", required_argument, NULL, 2},
                {"section", required_argument, NULL, 3},
                {"strict-names", no_argument, &strict_names, 1},
                {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
+               {"no-comments", no_argument, &no_comments, 1},
+               {"no-publications", no_argument, &no_publications, 1},
                {"no-security-labels", no_argument, &no_security_labels, 1},
+               {"no-subscriptions", no_argument, &no_subscriptions, 1},
 
                {NULL, 0, NULL, 0}
        };
 
+       pg_logging_init(argv[0]);
+       pg_logging_set_level(PG_LOG_WARNING);
        set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_dump"));
 
        init_parallel_dump_utils();
@@ -248,6 +251,7 @@ main(int argc, char **argv)
 
                        case 'v':                       /* verbose */
                                opts->verbose = 1;
+                               pg_logging_set_level(PG_LOG_INFO);
                                break;
 
                        case 'w':
@@ -297,20 +301,26 @@ main(int argc, char **argv)
        /* Complain if any arguments remain */
        if (optind < argc)
        {
-               fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
-                               progname, argv[optind]);
+               pg_log_error("too many command-line arguments (first is \"%s\")",
+                                        argv[optind]);
                fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
                                progname);
                exit_nicely(1);
        }
 
+       /* Complain if neither -f nor -d was specified (except if dumping TOC) */
+       if (!opts->dbname && !opts->filename && !opts->tocSummary)
+       {
+               pg_log_error("one of -d/--dbname and -f/--file must be specified");
+               exit_nicely(1);
+       }
+
        /* Should get at most one of -d and -f, else user is confused */
        if (opts->dbname)
        {
                if (opts->filename)
                {
-                       fprintf(stderr, _("%s: options -d/--dbname and -f/--file cannot be used together\n"),
-                                       progname);
+                       pg_log_error("options -d/--dbname and -f/--file cannot be used together");
                        fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
                                        progname);
                        exit_nicely(1);
@@ -320,21 +330,29 @@ main(int argc, char **argv)
 
        if (opts->dataOnly && opts->schemaOnly)
        {
-               fprintf(stderr, _("%s: options -s/--schema-only and -a/--data-only cannot be used together\n"),
-                               progname);
+               pg_log_error("options -s/--schema-only and -a/--data-only cannot be used together");
                exit_nicely(1);
        }
 
        if (opts->dataOnly && opts->dropSchema)
        {
-               fprintf(stderr, _("%s: options -c/--clean and -a/--data-only cannot be used together\n"),
-                               progname);
+               pg_log_error("options -c/--clean and -a/--data-only cannot be used together");
+               exit_nicely(1);
+       }
+
+       /*
+        * -C is not compatible with -1, because we can't create a database inside
+        * a transaction block.
+        */
+       if (opts->createDB && opts->single_txn)
+       {
+               pg_log_error("options -C/--create and -1/--single-transaction cannot be used together");
                exit_nicely(1);
        }
 
        if (numWorkers <= 0)
        {
-               fprintf(stderr, _("%s: invalid number of parallel jobs\n"), progname);
+               pg_log_error("invalid number of parallel jobs");
                exit(1);
        }
 
@@ -342,8 +360,8 @@ main(int argc, char **argv)
 #ifdef WIN32
        if (numWorkers > MAXIMUM_WAIT_OBJECTS)
        {
-               fprintf(stderr, _("%s: maximum number of parallel jobs is %d\n"),
-                               progname, MAXIMUM_WAIT_OBJECTS);
+               pg_log_error("maximum number of parallel jobs is %d",
+                                        MAXIMUM_WAIT_OBJECTS);
                exit(1);
        }
 #endif
@@ -351,23 +369,23 @@ main(int argc, char **argv)
        /* Can't do single-txn mode with multiple connections */
        if (opts->single_txn && numWorkers > 1)
        {
-               fprintf(stderr, _("%s: cannot specify both --single-transaction and multiple jobs\n"),
-                               progname);
+               pg_log_error("cannot specify both --single-transaction and multiple jobs");
                exit_nicely(1);
        }
 
        opts->disable_triggers = disable_triggers;
        opts->enable_row_security = enable_row_security;
-       opts->include_subscriptions = include_subscriptions;
        opts->noDataForFailedTables = no_data_for_failed_tables;
        opts->noTablespace = outputNoTablespaces;
        opts->use_setsessauth = use_setsessauth;
+       opts->no_comments = no_comments;
+       opts->no_publications = no_publications;
        opts->no_security_labels = no_security_labels;
+       opts->no_subscriptions = no_subscriptions;
 
        if (if_exists && !opts->dropSchema)
        {
-               fprintf(stderr, _("%s: option --if-exists requires option -c/--clean\n"),
-                               progname);
+               pg_log_error("option --if-exists requires option -c/--clean");
                exit_nicely(1);
        }
        opts->if_exists = if_exists;
@@ -393,7 +411,7 @@ main(int argc, char **argv)
                                break;
 
                        default:
-                               write_msg(NULL, "unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"\n",
+                               pg_log_error("unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
                                                  opts->formatName);
                                exit_nicely(1);
                }
@@ -433,8 +451,7 @@ main(int argc, char **argv)
 
        /* done, print a summary of ignored errors */
        if (AH->n_errors)
-               fprintf(stderr, _("WARNING: errors ignored on restore: %d\n"),
-                               AH->n_errors);
+               pg_log_warning("errors ignored on restore: %d", AH->n_errors);
 
        /* AH may be freed in CloseArchive? */
        exit_code = AH->n_errors ? 1 : 0;
@@ -453,7 +470,7 @@ usage(const char *progname)
 
        printf(_("\nGeneral options:\n"));
        printf(_("  -d, --dbname=NAME        connect to database name\n"));
-       printf(_("  -f, --file=FILENAME      output file name\n"));
+       printf(_("  -f, --file=FILENAME      output file name (- for stdout)\n"));
        printf(_("  -F, --format=c|d|t       backup file format (should be automatic)\n"));
        printf(_("  -l, --list               print summarized TOC of the archive\n"));
        printf(_("  -v, --verbose            verbose mode\n"));
@@ -482,13 +499,16 @@ usage(const char *progname)
        printf(_("  --disable-triggers           disable triggers during data-only restore\n"));
        printf(_("  --enable-row-security        enable row security\n"));
        printf(_("  --if-exists                  use IF EXISTS when dropping objects\n"));
+       printf(_("  --no-comments                do not restore comments\n"));
        printf(_("  --no-data-for-failed-tables  do not restore data of tables that could not be\n"
                         "                               created\n"));
+       printf(_("  --no-publications            do not restore publications\n"));
        printf(_("  --no-security-labels         do not restore security labels\n"));
+       printf(_("  --no-subscriptions           do not restore subscriptions\n"));
        printf(_("  --no-tablespaces             do not restore tablespace assignments\n"));
        printf(_("  --section=SECTION            restore named section (pre-data, data, or post-data)\n"));
        printf(_("  --strict-names               require table and/or schema include patterns to\n"
-                "                               match at least one entity each\n"));
+                        "                               match at least one entity each\n"));
        printf(_("  --use-set-session-authorization\n"
                         "                               use SET SESSION AUTHORIZATION commands instead of\n"
                         "                               ALTER OWNER commands to set ownership\n"));
@@ -502,8 +522,8 @@ usage(const char *progname)
        printf(_("  --role=ROLENAME          do SET ROLE before restore\n"));
 
        printf(_("\n"
-                        "The options -I, -n, -P, -t, -T, and --section can be combined and specified\n"
+                        "The options -I, -n, -N, -P, -t, -T, and --section can be combined and specified\n"
                         "multiple times to select multiple objects.\n"));
        printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
-       printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
+       printf(_("Report bugs to <pgsql-bugs@lists.postgresql.org>.\n"));
 }