pg_isready_bin_v5.diff
application/octet-stream
Filename: pg_isready_bin_v5.diff
Type: application/octet-stream
Part: 0
Message:
Re: [WIP] pg_ping utility
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v5
| File | + | − |
|---|---|---|
| src/bin/scripts/.gitignore | 0 | 0 |
| src/bin/scripts/Makefile | 0 | 0 |
| src/bin/scripts/pg_isready.c | 0 | 0 |
diff --git a/src/bin/scripts/.gitignore b/src/bin/scripts/.gitignore
new file mode 100644
index e62f4b0..0b9b786
*** a/src/bin/scripts/.gitignore
--- b/src/bin/scripts/.gitignore
***************
*** 7,12 ****
--- 7,13 ----
/dropuser
/reindexdb
/vacuumdb
+ /pg_isready
/dumputils.c
/keywords.c
diff --git a/src/bin/scripts/Makefile b/src/bin/scripts/Makefile
new file mode 100644
index 0980b4c..cc9f2c0
*** a/src/bin/scripts/Makefile
--- b/src/bin/scripts/Makefile
*************** subdir = src/bin/scripts
*** 16,22 ****
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
! PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vacuumdb reindexdb
override CPPFLAGS := -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)
--- 16,22 ----
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
! PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vacuumdb reindexdb pg_isready
override CPPFLAGS := -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)
*************** dropuser: dropuser.o common.o dumputils.
*** 34,39 ****
--- 34,40 ----
clusterdb: clusterdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq
vacuumdb: vacuumdb.o common.o | submake-libpq
reindexdb: reindexdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq
+ pg_isready: pg_isready.o common.o | submake-libpq submake-libpgport
dumputils.c keywords.c: % : $(top_srcdir)/src/bin/pg_dump/%
rm -f $@ && $(LN_S) $< .
*************** install: all installdirs
*** 54,59 ****
--- 55,61 ----
$(INSTALL_PROGRAM) clusterdb$(X) '$(DESTDIR)$(bindir)'/clusterdb$(X)
$(INSTALL_PROGRAM) vacuumdb$(X) '$(DESTDIR)$(bindir)'/vacuumdb$(X)
$(INSTALL_PROGRAM) reindexdb$(X) '$(DESTDIR)$(bindir)'/reindexdb$(X)
+ $(INSTALL_PROGRAM) pg_isready$(X) '$(DESTDIR)$(bindir)'/pg_isready$(X)
installdirs:
$(MKDIR_P) '$(DESTDIR)$(bindir)'
diff --git a/src/bin/scripts/pg_isready.c b/src/bin/scripts/pg_isready.c
new file mode 100644
index ...8822ce3
*** a/src/bin/scripts/pg_isready.c
--- b/src/bin/scripts/pg_isready.c
***************
*** 0 ****
--- 1,178 ----
+ /*-------------------------------------------------------------------------
+ *
+ * pg_isready --- checks the status of the PostgreSQL server
+ *
+ * Copyright (c) 2012, PostgreSQL Global Development Group
+ *
+ * src/bin/scripts/pg_isready.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ #include "postgres_fe.h"
+ #include "common.h"
+
+ void
+ help(const char *progname);
+
+ int
+ main(int argc, char **argv)
+ {
+ int c,optindex,opt_index = 0;
+
+ const char *pghost = NULL;
+ const char *pgport = NULL;
+ const char *pguser = NULL;
+ const char *pgdbname = NULL;
+
+ const char *keywords[4], *values[4];
+
+ bool verbose = false;
+
+ PGPing rv;
+ PQconninfoOption *connect_options, *conn_opt_ptr;
+
+ static struct option long_options[] = {
+ {"dbname", required_argument, NULL, 'd'},
+ {"host", required_argument, NULL, 'h'},
+ {"port", required_argument, NULL, 'p'},
+ {"username", required_argument, NULL, 'U'},
+ {"verbose", no_argument, NULL, 'v'},
+ {NULL, 0, NULL, 0}
+ };
+
+ handle_help_version_opts(argc, argv, "pg_isready", help);
+
+ while ((c = getopt_long(argc, argv, "d:h:p:U:vV", long_options, &optindex)) != -1)
+ {
+ switch (c)
+ {
+ case 'd':
+ pgdbname = pg_strdup(optarg);
+ break;
+ case 'h':
+ pghost = pg_strdup(optarg);
+ break;
+ case 'p':
+ pgport = pg_strdup(optarg);
+ break;
+ case 'U':
+ pguser = pg_strdup(optarg);
+ break;
+ case 'v':
+ verbose = true;
+ break;
+ default:
+ /*
+ * We need to make sure we don't return 1 here because someone
+ * checking the return code might infer unintended meaning
+ */
+ exit(PQPING_NO_ATTEMPT);
+ }
+ }
+
+ connect_options = PQconndefaults();
+ conn_opt_ptr = connect_options;
+
+ while (conn_opt_ptr->keyword)
+ {
+ if (strncmp(conn_opt_ptr->keyword, "host", 5) == 0)
+ {
+ if (pghost)
+ {
+ keywords[opt_index] = conn_opt_ptr->keyword;
+ values[opt_index] = pghost;
+ opt_index++;
+ }
+ else if (conn_opt_ptr->val)
+ pghost = conn_opt_ptr->val;
+ else
+ pghost = DEFAULT_PGSOCKET_DIR;
+ }
+ else if (strncmp(conn_opt_ptr->keyword, "port", 5) == 0)
+ {
+ if (pgport)
+ {
+ keywords[opt_index] = conn_opt_ptr->keyword;
+ values[opt_index] = pgport;
+ opt_index++;
+ }
+ else if (conn_opt_ptr->val)
+ pgport = conn_opt_ptr->val;
+ }
+ else if (strncmp(conn_opt_ptr->keyword, "user", 5) == 0)
+ {
+ if (pguser)
+ {
+ keywords[opt_index] = conn_opt_ptr->keyword;
+ values[opt_index] = pguser;
+ opt_index++;
+ }
+ else if (conn_opt_ptr->val)
+ pguser = conn_opt_ptr->val;
+ }
+ else if (strncmp(conn_opt_ptr->keyword, "dbname", 7) == 0)
+ {
+ if (pgdbname)
+ {
+ keywords[opt_index] = conn_opt_ptr->keyword;
+ values[opt_index] = pgdbname;
+ opt_index++;
+ }
+ else if (conn_opt_ptr->val)
+ pgdbname = conn_opt_ptr->val;
+ }
+ conn_opt_ptr++;
+ }
+
+ keywords[opt_index] = NULL;
+ values[opt_index] = NULL;
+
+ rv = PQpingParams(keywords, values, 1);
+
+ if (verbose)
+ {
+ printf("%s:%s - ", pghost, pgport);
+
+ switch (rv)
+ {
+ case PQPING_OK:
+ printf("Accepting Connections\n");
+ break;
+ case PQPING_REJECT:
+ printf("Rejecting Connections\n");
+ break;
+ case PQPING_NO_RESPONSE:
+ printf("No Response\n");
+ break;
+ case PQPING_NO_ATTEMPT:
+ printf("No Attempt\n");
+ break;
+ default:
+ printf("Unknown\n");
+ }
+ }
+
+ PQconninfoFree(connect_options);
+
+ exit(rv);
+ }
+
+ void
+ help(const char *progname)
+ {
+ printf(_("%s issues a connection check to a PostgreSQL database.\n\n"), progname);
+ printf(_("Usage:\n"));
+ printf(_(" %s [OPTION]...\n"), progname);
+
+ printf(_("\nOptions:\n"));
+ printf(_(" -d, --dbname=DBNAME database name\n"));
+ printf(_(" -U, --username=USERNAME database username\n"));
+ printf(_(" -V, --version output version information, then exit\n"));
+ printf(_(" -v, --verbose output verbose messages\n"));
+ printf(_(" -?, --help show this help, then exit\n"));
+
+ printf(_("\nConnection options:\n"));
+ printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
+ printf(_(" -p, --port=PORT database server port\n"));
+ }