BUG #6682: pg_dump and sequence values of serial columns for extension configuration tables

From: phb(dot)emaj(at)free(dot)fr
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #6682: pg_dump and sequence values of serial columns for extension configuration tables
Date: 2012-06-09 06:57:22
Message-ID: E1SdFbu-0006NI-A6@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 6682
Logged by: Philippe BEAUDOIN
Email address: phb(dot)emaj(at)free(dot)fr
PostgreSQL version: 9.1.4
Operating system: Linux
Description:

When a table is registered as an extension configuration table and contains
a serial column, the current value of the sequence associated to this serial
column is not dumped by pg_dump.

Here is a test case to easily reproduce this issue.
Just copy/paste and adjust initial parameters.

#!/bin/sh

export PGINST=/usr/local/pg913
export PGBIN=$PGINST/bin
export PGEXT=$PGINST/share/postgresql/extension

export PGHOST=localhost
export PGPORT=5913
export PGUSER=postgres
export PGDATABASE=phb

echo
"-----------------------------------------------------------------------"
echo " Issue: pg_dump doesn't record sequence values of serial columns for
"
echo " tables registered by pg_extension_config_dump()"
echo
"-----------------------------------------------------------------------"
echo Connection parameters: $PGHOST - $PGPORT - $PGUSER - $PGDATABASE

# Build the extension control file
cat >$PGINST/share/postgresql/extension/phb.control <<EOF
default_version = '1.0.0'
schema = phb
EOF

# Create a test database
$PGBIN/psql template1 -ac "drop database phb;"
$PGBIN/psql template1 -ac "create database phb;"

# create the create extension script
cat >$PGEXT/phb--1.0.0.sql <<EOF
create table tbl1 (col1 serial not null primary key, col2 int);
select pg_catalog.pg_extension_config_dump('tbl1','');
create sequence seq1;
EOF

echo "--> Create the extension"
$PGBIN/psql -ac "create extension phb;"
$PGBIN/psql -ac "\dx+ phb"

echo "--> Use the extension and look at the impact"
$PGBIN/psql -ac "insert into phb.tbl1 (col2) values (1),(2),(3);"
$PGBIN/psql -ac "select setval('phb.seq1',10);"
$PGBIN/psql -ac "select * from phb.tbl1;"
$PGBIN/psql -ac "select * from phb.tbl1_col1_seq;"
$PGBIN/psql -ac "select * from phb.seq1;"

echo "--> OK, now dump the phb database"
$PGBIN/pg_dump -Fp -f phb.dump

echo "--> Cleanup and recreate the database"
$PGBIN/psql template1 -ac "drop database phb;"
$PGBIN/psql template1 -ac "create database phb;"

echo "--> Restore the phb database"
$PGBIN/psql -f phb.dump

echo "--> Look at the result: the sequences start values equal 1 !!! "
$PGBIN/psql -ac "\dx+ phb"
$PGBIN/psql -ac "select * from phb.tbl1;"
$PGBIN/psql -ac "select * from phb.tbl1_col1_seq;"
$PGBIN/psql -ac "select * from phb.seq1;"

echo "--> Of course inserting a new row results in duplicate key errors"
$PGBIN/psql -ac "insert into phb.tbl1 (col2) values (4);"

echo "--> And sequences cannot be registered as 'content to be dumped'"
$PGBIN/psql -ac "select
pg_catalog.pg_extension_config_dump('tbl1_col1_seq','');"
$PGBIN/psql -ac "select pg_catalog.pg_extension_config_dump('seq1','');"

# cleanup the environment
$PGBIN/psql template1 -ac "drop database phb;"
rm $PGINST/share/postgresql/extension/phb*
rm phb.dump

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message phb.emaj 2012-06-09 07:06:35 BUG #6683: dropping a table with a serial column from an extension needs to explicitely drop the associated seq
Previous Message phb.emaj 2012-06-09 06:52:24 BUG #6681: pg_extension.extconfig after alter sequence drop table