Skip to content

Commit

Permalink
Add backend_type column to postgres_log if it is missing on postgres …
Browse files Browse the repository at this point in the history
…13 (#573)

Due to the bug in the upgrade script postgres_log table wasn't dropped before pg_upgrade. As a result it wasn't recreated with the new structure.
In order to fix it, the post_init.sh running against Postgres 13 script will always try to add a column with NOT EXISTS.

At the same time we simplify the upgrade script. We don't need to drop the postgres_log foreign table before the upgrade.
  • Loading branch information
CyberDem0n authored Mar 26, 2021
1 parent 97febca commit 9cbf209
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 1 addition & 3 deletions postgres-appliance/major_upgrade/pg_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def drop_possibly_incompatible_objects(self):
for ext in ('pg_stat_kcache', 'pg_stat_statements') + self._INCOMPATIBLE_EXTENSIONS:
logger.info('Executing "DROP EXTENSION IF EXISTS %s" in the database="%s"', ext, d)
cur.execute("DROP EXTENSION IF EXISTS {0}".format(ext))
if d[0] == 'postgres':
logger.info('Executing "DROP TABLE postgres_log CASCADE" in the database=postgres')
cur.execute('DROP TABLE IF EXISTS public.postgres_log CASCADE')

cur.execute("SELECT oid::regclass FROM pg_catalog.pg_class WHERE relpersistence = 'u'")
for unlogged in cur.fetchall():
logger.info('Truncating unlogged table %s', unlogged[0])
Expand Down
8 changes: 5 additions & 3 deletions postgres-appliance/scripts/post_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ CREATE TABLE IF NOT EXISTS public.postgres_log (
query text,
query_pos integer,
location text,
application_name text,"
if [ "$PGVER" -ge 13 ]; then echo " backend_type text,"; fi
echo " CONSTRAINT postgres_log_check CHECK (false) NO INHERIT
application_name text,
CONSTRAINT postgres_log_check CHECK (false) NO INHERIT
);
GRANT SELECT ON public.postgres_log TO admin;"
if [ "$PGVER" -ge 13 ]; then
echo "ALTER TABLE public.postgres_log ADD COLUMN IF NOT EXISTS backend_type text;"
fi

# Sunday could be 0 or 7 depending on the format, we just create both
for i in $(seq 0 7); do
Expand Down

0 comments on commit 9cbf209

Please sign in to comment.