pg_dump excluding tables content but not table schema

Started by Ivan Sergio Borgonovoover 16 years ago14 messagesgeneral
Jump to latest
#1Ivan Sergio Borgonovo
mail@webthatworks.it

I've some tables that are just cache.

I'd like to just dump the table schema without dumping the table
contend.

I think I could do it in 2 steps but I'd like to avoid it.

Is there a way?

thanks

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

In reply to: Ivan Sergio Borgonovo (#1)
Re: pg_dump excluding tables content but not table schema

On 28/12/2009 18:41, Ivan Sergio Borgonovo wrote:

I'd like to just dump the table schema without dumping the table
contend.

pg_dump -s -t <table name> <db name>

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

#3Ivan Sergio Borgonovo
mail@webthatworks.it
In reply to: Raymond O'Donnell (#2)
Re: pg_dump excluding tables content but not table schema

On Mon, 28 Dec 2009 19:39:36 +0000
Raymond O'Donnell <rod@iol.ie> wrote:

On 28/12/2009 18:41, Ivan Sergio Borgonovo wrote:

I'd like to just dump the table schema without dumping the table
contend.

pg_dump -s -t <table name> <db name>

My fault. I was not clear enough.
I'd like to make a "mostly" full backup, excluding from backup just
the data of some tables but backing up the schema of those tables.

mmm let me try if

pg_dump -Fc -Z9 -s -t *.cache* -d mydb > schema_only.bak
pg_dump -Fc -Z9 -T *.cache* -d mydb > nearly_full.bak

cat nearly_full.bak schema_only.bak | pg_restore -1 -d mydb

It seems it is working... I'll test if everything is there.

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

In reply to: Ivan Sergio Borgonovo (#3)
Re: pg_dump excluding tables content but not table schema

On 28/12/2009 20:20, Ivan Sergio Borgonovo wrote:

On Mon, 28 Dec 2009 19:39:36 +0000
Raymond O'Donnell <rod@iol.ie> wrote:

On 28/12/2009 18:41, Ivan Sergio Borgonovo wrote:

I'd like to just dump the table schema without dumping the table
contend.

pg_dump -s -t <table name> <db name>

My fault. I was not clear enough.
I'd like to make a "mostly" full backup, excluding from backup just
the data of some tables but backing up the schema of those tables.

mmm let me try if

pg_dump -Fc -Z9 -s -t *.cache* -d mydb > schema_only.bak
pg_dump -Fc -Z9 -T *.cache* -d mydb > nearly_full.bak

cat nearly_full.bak schema_only.bak | pg_restore -1 -d mydb

It seems it is working... I'll test if everything is there.

I don't think you can do it in one step with a single invocation of
pg_dump - I reckon what you've come up with there is the way to go.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

#5Gastón Quiroga
gastonq@allytech.com
In reply to: Raymond O'Donnell (#4)
pg_dump ERROR, usename "postgres" duplicated

Hi:
I cannot dump any database from my server. When I try to do it i
receive this error

pg_dump: The command was: SELECT tableoid, oid, nspname, (select usename
from pg_user where nspowner = usesysid) as usename, nspacl FROM pg_namespace

I checked the pg_user database and I found this:

postgres=# select * from pg_user;
usename | usesysid | usecreatedb | usesuper | usecatupd |
passwd | valuntil | useconfig
---------------+----------+-------------+----------+-----------+----------+----------+-----------
postgres | 1 | t | t | t |
******** | |
postgres | 1 | t | t | t |
******** | |
administrador | 100 | t | t | t |
******** | |
user1 | 101 | t | t | t |
******** | |
user2 | 102 | f | f | f |
******** | |

Anyone can tell me from where should I start?. This is a production
server.

Regards.

--
Gast�n Quiroga

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Gastón Quiroga (#5)
Re: pg_dump ERROR, usename "postgres" duplicated

=?ISO-8859-1?Q?Gast=F3n_Quiroga?= <gastonq@allytech.com> writes:

I checked the pg_user database and I found this:

postgres=# select * from pg_user;
usename | usesysid | usecreatedb | usesuper | usecatupd |
passwd | valuntil | useconfig
---------------+----------+-------------+----------+-----------+----------+----------+-----------
postgres | 1 | t | t | t |
******** | |
postgres | 1 | t | t | t |
******** | |
administrador | 100 | t | t | t |
******** | |

What PG version is that? (Apparently pre-8.1, but what exactly?)

It would be useful to look at the underlying table:

select ctid,xmin,xmax,* from pg_shadow;

regards, tom lane

#7Gastón
tango@allytech.com
In reply to: Tom Lane (#6)
Re: pg_dump ERROR, usename "postgres" duplicated

Thanks for your reply Tom, and sorry for the duplicated e-mails.

It's Postgres version 8.0.8

Thank you

Gast�n Quiroga
Allytech S.A.

Tom Lane wrote:

Show quoted text

=?ISO-8859-1?Q?Gast=F3n_Quiroga?= <gastonq@allytech.com> writes:

I checked the pg_user database and I found this:

postgres=# select * from pg_user;
usename | usesysid | usecreatedb | usesuper | usecatupd |
passwd | valuntil | useconfig
---------------+----------+-------------+----------+-----------+----------+----------+-----------
postgres | 1 | t | t | t |
******** | |
postgres | 1 | t | t | t |
******** | |
administrador | 100 | t | t | t |
******** | |

What PG version is that? (Apparently pre-8.1, but what exactly?)

It would be useful to look at the underlying table:

select ctid,xmin,xmax,* from pg_shadow;

regards, tom lane

#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Gastón (#7)
Re: pg_dump ERROR, usename "postgres" duplicated

=?ISO-8859-1?Q?Gast=F3n?= <tango@allytech.com> writes:

It's Postgres version 8.0.8

Well, that's pretty ancient, and I see at least one bug in the release
history that could result in duplicated rows. I'd counsel an update to
8.0.something-recent. You can probably delete the extra row using
a WHERE on ctid.

regards, tom lane

#9Gastón Quiroga
gastonq@allytech.com
In reply to: Tom Lane (#8)
Re: pg_dump ERROR, usename "postgres" duplicated

Thank You Tom:
I'll Try to make an update, but the 2 fields are equals row by row,
how could I make a difference in the "WHERE" statement?

Regards

Gast�n Quiroga
Allytech S.A.

Tom Lane wrote:

Show quoted text

=?ISO-8859-1?Q?Gast=F3n?= <tango@allytech.com> writes:

It's Postgres version 8.0.8

Well, that's pretty ancient, and I see at least one bug in the release
history that could result in duplicated rows. I'd counsel an update to
8.0.something-recent. You can probably delete the extra row using
a WHERE on ctid.

regards, tom lane

#10Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Gastón Quiroga (#9)
Re: pg_dump ERROR, usename "postgres" duplicated

Gast�n Quiroga wrote:

Thank You Tom:
I'll Try to make an update, but the 2 fields are equals row by
row, how could I make a difference in the "WHERE" statement?

Use the ctid hidden system field.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#11Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Gastón Quiroga (#9)
Re: pg_dump ERROR, usename "postgres" duplicated

----- "Gastón Quiroga" <gastonq@allytech.com> wrote:

Thank You Tom:
I'll Try to make an update, but the 2 fields are equals row by row,
how could I make a difference in the "WHERE" statement?

Regards

Gastón Quiroga
Allytech S.A.

Tom Lane wrote:

=?ISO-8859-1?Q?Gast=F3n?= <tango@allytech.com> writes:

It's Postgres version 8.0.8 Well, that's pretty ancient, and I see at
least one bug in the release
history that could result in duplicated rows. I'd counsel an update
to
8.0.something-recent. You can probably delete the extra row using
a WHERE on ctid.

regards, tom lane

Per Toms previous post use the following query:
select ctid,xmin,xmax,* from pg_shadow;

Then use the ctid value of the duplicate value in the where clause.

Adrian Klaver
aklaver@comcast.net

#12Gastón Quiroga
gastonq@allytech.com
In reply to: Adrian Klaver (#11)
Re: pg_dump ERROR, usename "postgres" duplicated

The upgrade works, thank you all !

Gastón Quiroga
Allytech S.A.

Adrian Klaver wrote:

Show quoted text

----- "Gastón Quiroga" <gastonq@allytech.com> wrote:

Thank You Tom:
I'll Try to make an update, but the 2 fields are equals row by row,
how could I make a difference in the "WHERE" statement?

Regards

Gastón Quiroga
Allytech S.A.

Tom Lane wrote:

=?ISO-8859-1?Q?Gast=F3n?= <tango@allytech.com> writes:

It's Postgres version 8.0.8 Well, that's pretty ancient, and I see at
least one bug in the release
history that could result in duplicated rows. I'd counsel an update
to
8.0.something-recent. You can probably delete the extra row using
a WHERE on ctid.

regards, tom lane

Per Toms previous post use the following query:
select ctid,xmin,xmax,* from pg_shadow;

Then use the ctid value of the duplicate value in the where clause.

Adrian Klaver
aklaver@comcast.net

#13Ivan Sergio Borgonovo
mail@webthatworks.it
In reply to: Ivan Sergio Borgonovo (#3)
Re: pg_dump excluding tables content but not table schema

On Mon, 28 Dec 2009 21:20:17 +0100
Ivan Sergio Borgonovo <mail@webthatworks.it> wrote:

pg_dump -Fc -Z9 -s -t *.cache* -d mydb > schema_only.bak
pg_dump -Fc -Z9 -T *.cache* -d mydb > nearly_full.bak

cat nearly_full.bak schema_only.bak | pg_restore -1 -d mydb

It seems it is working... I'll test if everything is there.

Unfortunately it doesn't work as expected.
It silently skip to restore the second backup (schema_only.bak).
I'm surprised it didn't output any error message, but the cache
tables aren't there.

It seems that you have to actually restore the 2 backup separately.

pg_restore -1 -d mydb < nearly_full.bak
pg_restore -1 -d mydb < schema_only.bak

I can't think of any other way to restore both in one transaction
unless I backup in plain text. But that should have other drawback.

Any hint?

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

#14Dimitri Fontaine
dimitri@2ndQuadrant.fr
In reply to: Ivan Sergio Borgonovo (#13)
Re: pg_dump excluding tables content but not table schema

Ivan Sergio Borgonovo <mail@webthatworks.it> writes:

It seems that you have to actually restore the 2 backup separately.

pg_restore -1 -d mydb < nearly_full.bak
pg_restore -1 -d mydb < schema_only.bak

I can't think of any other way to restore both in one transaction
unless I backup in plain text. But that should have other drawback.

Any hint?

In general what I do is backup it all then filter at restore time,
editing the restore catalog (see pg_restore options -l and
-L).

Incidentally I've written code for automating this for me, that's called
pg_staging and is available at github and already is in debian (I miss a
source release so that RPM will follow):

http://github.com/dimitri/pg_staging

Regards,
--
dim