Created
October 18, 2012 17:52
-
-
Save vinnix/3913729 to your computer and use it in GitHub Desktop.
weird pg_restore behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Looking about a weird scenario, when I try to restore only one table from a dump, | |
but the restore does not work, without any errors. | |
$ psql -d postgres | |
psql (9.1.3) | |
Type "help" for help. | |
postgres=# create database my_poc; | |
CREATE DATABASE | |
postgres=# not null default nextval('testschema.testtable_id_seq'::regclass) | |
postgres=# \c my_poc | |
You are now connected to database "my_poc" as user "pgsql". | |
my_poc=# create schema testschema; | |
CREATE SCHEMA | |
my_poc=# CREATE TABLE testschema.testtable | |
my_poc-# ( | |
my_poc(# id serial, | |
my_poc(# name character varying(255), | |
my_poc(# CONSTRAINT pk_testtable PRIMARY KEY (id) | |
my_poc(# ) | |
my_poc-# WITH ( | |
my_poc(# OIDS = FALSE | |
my_poc(# ) | |
my_poc-# ; | |
NOTICE: CREATE TABLE will create implicit sequence "testtable_id_seq" for serial column "testtable.id" | |
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_testtable" for table "testtable" | |
CREATE TABLE | |
my_poc=# insert into testschema.testtable (name) values ('nome1'),('nome2'),('nome3'); | |
INSERT 0 3 | |
my_poc=# \d testschema.testtable | |
Table "testschema.testtable" | |
Column | Type | Modifiers | |
--------+------------------------+------------------------------------------------------------------- | |
id | integer | not null default nextval('testschema.testtable_id_seq'::regclass) | |
name | character varying(255) | | |
Indexes: | |
"pk_testtable" PRIMARY KEY, btree (id) | |
So far so good, let's observe that I have a default value (for the sequence). | |
Then I create the dump.... | |
$ pg_dump -U postgres -Fc -b -f my_poc.dump my_poc | |
$ pg_restore -l my_poc.dump | |
; | |
; Archive created at Thu Oct 18 14:20:43 2012 | |
; dbname: my_poc | |
; TOC Entries: 16 | |
; Compression: -1 | |
; Dump Version: 1.12-0 | |
; Format: CUSTOM | |
; Integer: 4 bytes | |
; Offset: 8 bytes | |
; Dumped from database version: 9.1.3 | |
; Dumped by pg_dump version: 9.1.3 | |
; | |
; | |
; Selected TOC Entries: | |
; | |
2169; 1262 50650175 DATABASE - my_poc pgsql | |
6; 2615 2200 SCHEMA - public pgsql | |
2170; 0 0 COMMENT - SCHEMA public pgsql | |
2171; 0 0 ACL - public pgsql | |
7; 2615 50650354 SCHEMA - testschema pgsql | |
164; 3079 11955 EXTENSION - plpgsql | |
2172; 0 0 COMMENT - EXTENSION plpgsql | |
163; 1259 50650357 TABLE testschema testtable pgsql | |
162; 1259 50650355 SEQUENCE testschema testtable_id_seq pgsql | |
2173; 0 0 SEQUENCE OWNED BY testschema testtable_id_seq pgsql | |
2174; 0 0 SEQUENCE SET testschema testtable_id_seq pgsql | |
2163; 2604 50650360 DEFAULT testschema id pgsql | |
2166; 0 50650357 TABLE DATA testschema testtable pgsql | |
2165; 2606 50650362 CONSTRAINT testschema pk_testtable pgsql | |
-- ---------------------------------------------------------------------------------------- | |
Then, I tried to reproduce the error... | |
besides pg_restore have worked fine, it does not create the table in the right schema | |
and do not create the sequence and the default value... | |
$ pg_restore -t testschema.testtable -d my_poc2 my_poc.dump | |
$ psql -d postgres | |
psql (9.1.3) | |
Type "help" for help. | |
postgres=# \c my_poc2 | |
You are now connected to database "my_poc2" as user "pgsql". | |
my_poc2=# \d | |
List of relations | |
Schema | Name | Type | Owner | |
--------+-----------+-------+------- | |
public | testtable | table | pgsql | |
(1 row) | |
my_poc2=# \d+ testtable | |
Table "public.testtable" | |
Column | Type | Modifiers | Storage | Description | |
--------+------------------------+-----------+----------+------------- | |
id | integer | not null | plain | | |
name | character varying(255) | | extended | | |
Has OIDs: no | |
my_poc2=# select * from testtable; | |
id | name | |
----+------- | |
1 | nome1 | |
2 | nome2 | |
3 | nome3 | |
(3 rows) | |
--------------------------------------------------------------------------------------------------- | |
then I tried to run more tests.. (including pass -n testschema) but the restore stoped to work... | |
$ createdb my_poc3 | |
$ pg_restore -v -t testschema.testtable -d my_poc3 my_poc.dump | |
pg_restore: connecting to database for restore | |
pg_restore: implied data-only restore | |
$ psql my_poc3 | |
psql (9.1.3) | |
Type "help" for help. | |
my_poc3=# \d | |
No relations found. | |
my_poc3=# \dn | |
List of schemas | |
Name | Owner | |
--------+------- | |
public | pgsql | |
(1 row) | |
my_poc3=# | |
---------------------------------------------------------------------------------------------------- | |
$ createdb my_poc5 | |
$ pg_restore -v -t testschema.testtable -d my_poc5 my_poc.dump | |
pg_restore: connecting to database for restore | |
pg_restore: implied data-only restore | |
$ psql my_poc5 | |
psql (9.1.3) | |
Type "help" for help. | |
my_poc5=# \d | |
No relations found. | |
my_poc5=# \q | |
$ | |
$ pg_restore -l my_poc.dump | |
; | |
; Archive created at Thu Oct 18 14:20:43 2012 | |
; dbname: my_poc | |
; TOC Entries: 16 | |
; Compression: -1 | |
; Dump Version: 1.12-0 | |
; Format: CUSTOM | |
; Integer: 4 bytes | |
; Offset: 8 bytes | |
; Dumped from database version: 9.1.3 | |
; Dumped by pg_dump version: 9.1.3 | |
; | |
; | |
; Selected TOC Entries: | |
; | |
2169; 1262 50650175 DATABASE - my_poc pgsql | |
6; 2615 2200 SCHEMA - public pgsql | |
2170; 0 0 COMMENT - SCHEMA public pgsql | |
2171; 0 0 ACL - public pgsql | |
7; 2615 50650354 SCHEMA - testschema pgsql | |
164; 3079 11955 EXTENSION - plpgsql | |
2172; 0 0 COMMENT - EXTENSION plpgsql | |
163; 1259 50650357 TABLE testschema testtable pgsql | |
162; 1259 50650355 SEQUENCE testschema testtable_id_seq pgsql | |
2173; 0 0 SEQUENCE OWNED BY testschema testtable_id_seq pgsql | |
2174; 0 0 SEQUENCE SET testschema testtable_id_seq pgsql | |
2163; 2604 50650360 DEFAULT testschema id pgsql | |
2166; 0 50650357 TABLE DATA testschema testtable pgsql | |
2165; 2606 50650362 CONSTRAINT testschema pk_testtable pgsql | |
$ pg_restore -v -t testschema.testtable -d my_poc5 my_poc.dump | |
pg_restore: connecting to database for restore | |
pg_restore: implied data-only restore | |
$ psql my_poc5 | |
psql (9.1.3) | |
Type "help" for help. | |
my_poc5=# \d | |
No relations found. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment