Skip to content

Commit b3304b8

Browse files
committed
Merge branch 'logging-cleanup'
2 parents 0e74882 + 08a8c94 commit b3304b8

File tree

3 files changed

+32
-37
lines changed

3 files changed

+32
-37
lines changed

bin/expected/repack.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,14 @@ SELECT * FROM tbl_with_dropped_toast;
115115
-- do repack
116116
--
117117
\! pg_repack --dbname=contrib_regression --table=tbl_badindex
118+
INFO: repacking table "tbl_badindex"
118119
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
119120
\! pg_repack --dbname=contrib_regression
121+
INFO: repacking table "tbl_cluster"
122+
INFO: repacking table "tbl_with_dropped_column"
123+
INFO: repacking table "tbl_with_dropped_toast"
120124
\! pg_repack --dbname=contrib_regression --table=tbl_cluster
125+
INFO: repacking table "tbl_cluster"
121126
--
122127
-- after
123128
--
@@ -308,8 +313,10 @@ WARNING: relation "tbl_nn" must have a primary key or not-null unique keys
308313
WARNING: relation "tbl_uk" must have a primary key or not-null unique keys
309314
-- => WARNING
310315
\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk
316+
INFO: repacking table "tbl_nn_uk"
311317
-- => OK
312318
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk
319+
INFO: repacking table "tbl_pk_uk"
313320
-- => OK
314321
\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
315322
WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys
@@ -326,6 +333,7 @@ SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::
326333
(1 row)
327334

328335
\! pg_repack --dbname=contrib_regression --table=issue3_1
336+
INFO: repacking table "issue3_1"
329337
CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL);
330338
CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops);
331339
SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid);
@@ -335,6 +343,7 @@ SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::
335343
(1 row)
336344

337345
\! pg_repack --dbname=contrib_regression --table=issue3_2
346+
INFO: repacking table "issue3_2"
338347
CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL);
339348
CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC);
340349
SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid);
@@ -344,6 +353,7 @@ SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::
344353
(1 row)
345354

346355
\! pg_repack --dbname=contrib_regression --table=issue3_3
356+
INFO: repacking table "issue3_3"
347357
CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL);
348358
CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST);
349359
SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid);
@@ -353,6 +363,7 @@ SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::
353363
(1 row)
354364

355365
\! pg_repack --dbname=contrib_regression --table=issue3_4
366+
INFO: repacking table "issue3_4"
356367
CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL);
357368
CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC);
358369
SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid);
@@ -362,3 +373,4 @@ SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::
362373
(1 row)
363374

364375
\! pg_repack --dbname=contrib_regression --table=issue3_5
376+
INFO: repacking table "issue3_5"

bin/expected/tablespace.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ INSERT INTO testts1 (data) values ('b');
1818
INSERT INTO testts1 (data) values ('c');
1919
-- can move the tablespace from default
2020
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts
21+
INFO: repacking table "testts1"
2122
SELECT relname, spcname
2223
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
2324
WHERE relname ~ '^testts1'
@@ -37,6 +38,7 @@ SELECT * from testts1 order by id;
3738

3839
-- tablespace stays where it is
3940
\! pg_repack --dbname=contrib_regression --no-order --table=testts1
41+
INFO: repacking table "testts1"
4042
SELECT relname, spcname
4143
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
4244
WHERE relname ~ '^testts1'
@@ -48,6 +50,7 @@ ORDER BY relname;
4850

4951
-- can move the ts back to default
5052
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default
53+
INFO: repacking table "testts1"
5154
SELECT relname, spcname
5255
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
5356
WHERE relname ~ '^testts1'
@@ -58,6 +61,7 @@ ORDER BY relname;
5861

5962
-- can move the table together with the indexes
6063
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx
64+
INFO: repacking table "testts1"
6165
SELECT relname, spcname
6266
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
6367
WHERE relname ~ '^testts1'

bin/pg_repack.c

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ static bool kill_ddl(PGconn *conn, Oid relid, bool terminate);
186186
static bool lock_access_share(PGconn *conn, Oid relid, const char *target_name);
187187

188188
#define SQLSTATE_INVALID_SCHEMA_NAME "3F000"
189+
#define SQLSTATE_UNDEFINED_FUNCTION "42883"
189190
#define SQLSTATE_QUERY_CANCELED "57014"
190191

191192
static bool sqlstate_equals(PGresult *res, const char *state)
@@ -364,22 +365,10 @@ repack_all_databases(const char *orderby)
364365

365366
dbname = PQgetvalue(result, i, 0);
366367

367-
if (pgut_log_level >= INFO)
368-
{
369-
printf("%s: repack database \"%s\"\n", PROGRAM_NAME, dbname);
370-
fflush(stdout);
371-
}
372-
368+
elog(INFO, "repacking database \"%s\"", dbname);
373369
ret = repack_one_database(orderby, errbuf, sizeof(errbuf));
374-
375-
if (pgut_log_level >= INFO)
376-
{
377-
if (ret)
378-
printf("\n");
379-
else
380-
printf(" ... skipped: %s\n", errbuf);
381-
fflush(stdout);
382-
}
370+
if (!ret)
371+
elog(INFO, "database \"%s\" skipped: %s", dbname, errbuf);
383372
}
384373

385374
CLEARPGRES(result);
@@ -477,12 +466,16 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
477466
}
478467
else
479468
{
480-
if (sqlstate_equals(res, SQLSTATE_INVALID_SCHEMA_NAME))
469+
if (sqlstate_equals(res, SQLSTATE_INVALID_SCHEMA_NAME)
470+
|| sqlstate_equals(res, SQLSTATE_UNDEFINED_FUNCTION))
481471
{
482-
/* Schema repack does not exist. Skip the database. */
472+
/* Schema repack does not exist, or version too old (version
473+
* functions not found). Skip the database.
474+
*/
483475
if (errbuf)
484476
snprintf(errbuf, errsize,
485-
"%s is not installed in the database", PROGRAM_NAME);
477+
"%s %s is not installed in the database",
478+
PROGRAM_NAME, PROGRAM_VERSION);
486479
}
487480
else
488481
{
@@ -547,19 +540,9 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
547540
/* on error skip the database */
548541
if (PQresultStatus(res) != PGRES_TUPLES_OK)
549542
{
550-
if (sqlstate_equals(res, SQLSTATE_INVALID_SCHEMA_NAME))
551-
{
552-
/* Schema repack does not exist. Skip the database. */
553-
if (errbuf)
554-
snprintf(errbuf, errsize,
555-
"%s is not installed in the database", PROGRAM_NAME);
556-
}
557-
else
558-
{
559-
/* Return the error message otherwise */
560-
if (errbuf)
561-
snprintf(errbuf, errsize, "%s", PQerrorMessage(connection));
562-
}
543+
/* Return the error message otherwise */
544+
if (errbuf)
545+
snprintf(errbuf, errsize, "%s", PQerrorMessage(connection));
563546
goto cleanup;
564547
}
565548

@@ -935,6 +918,8 @@ repack_one_table(const repack_table *table, const char *orderby)
935918

936919
initStringInfo(&sql);
937920

921+
elog(INFO, "repacking table \"%s\"", table->target_name);
922+
938923
elog(DEBUG2, "---- repack_one_table ----");
939924
elog(DEBUG2, "target_name : %s", table->target_name);
940925
elog(DEBUG2, "target_oid : %u", table->target_oid);
@@ -1029,12 +1014,6 @@ repack_one_table(const repack_table *table, const char *orderby)
10291014
* pg_locks momentarily.
10301015
*/
10311016
res = pgut_execute(conn2, "SELECT pg_backend_pid()", 0, NULL);
1032-
if (PQresultStatus(res) != PGRES_TUPLES_OK)
1033-
{
1034-
printf("%s", PQerrorMessage(conn2));
1035-
have_error = true;
1036-
goto cleanup;
1037-
}
10381017
buffer[0] = '\0';
10391018
strncat(buffer, PQgetvalue(res, 0, 0), sizeof(buffer) - 1);
10401019
CLEARPGRES(res);

0 commit comments

Comments
 (0)