473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dump/Restore ordering problem?


First I created a function that selected the next available pin
code from a table of pre-defined pin codes:

CREATE FUNCTION "public"."get_next_pin_code" () RETURNS varchar AS'
DECLARE
my_pin_code VARCHAR;
BEGIN
...
/* this is the pincode we just fetched */
RETURN (my_pin_code);
END;
'LANGUAGE 'plpgsql';

Then I created a table that used that function to set a default value:

CREATE TABLE "public"."account" (
"acct_id" BIGSERIAL,
...,
"acct_pin_code" VARCHAR(16) NOT NULL DEFAULT get_next_pin_code()
) WITH OIDS;

But, now when I pg_dump and pg_restore this database to another server,
there seems to be a problem with the ordering of the dump in that the
account table is not recreated because the function get_next_pin_code()
is not yet defined. It seems like the function is not being created
until AFTER the table is created and this causes an ordering problem.

To dump and restore I've been doing this:

pg_dump -U dbuser -Ft dbname | pg_restore -c -Ft | psql -U dbuser -h
db.otherdbhost.com dbname

I've been able to work around this by creating a TRIGGER that sets the
default value instead of defining it in the table definition, but that
just seems like a hack. Is there something I need to do to make the
dependency ordering work smarter during a dump/restore? Or is this the
right way to do it?

Dante


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #1
2 2527
Dear D. Dante Lorenso ,

pg_dump the schema alone and the data alone in two different files
with commands
pg_dump -R -s -F p -f my_schema.sql -U <username> <dbname> <----
for Schema
pg_dump --disable-triggers -U <username> -a -d -b -D -Fc Z 9
my_data.tar.gz <dbname> <--for data

Now restructure your schema file such that functions are created first .

Hope this helps
Regards ,
Vishal Kashyap

First I created a function that selected the next available pin
code from a table of pre-defined pin codes:

CREATE FUNCTION "public"."get_next_pin_code" () RETURNS varchar AS'
DECLARE
my_pin_code VARCHAR;
BEGIN
...
/* this is the pincode we just fetched */
RETURN (my_pin_code);
END;
'LANGUAGE 'plpgsql';

Then I created a table that used that function to set a default value:

CREATE TABLE "public"."account" (
"acct_id" BIGSERIAL,
...,
"acct_pin_code" VARCHAR(16) NOT NULL DEFAULT get_next_pin_code()
) WITH OIDS;

But, now when I pg_dump and pg_restore this database to another server,
there seems to be a problem with the ordering of the dump in that the
account table is not recreated because the function get_next_pin_code()
is not yet defined. It seems like the function is not being created
until AFTER the table is created and this causes an ordering problem.

To dump and restore I've been doing this:

pg_dump -U dbuser -Ft dbname | pg_restore -c -Ft | psql -U dbuser
-h db.otherdbhost.com dbname

I've been able to work around this by creating a TRIGGER that sets the
default value instead of defining it in the table definition, but that
just seems like a hack. Is there something I need to do to make the
dependency ordering work smarter during a dump/restore? Or is this the
right way to do it?

Dante


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #2
"D. Dante Lorenso" <da***@lorenso.com> writes:
Is there something I need to do to make the
dependency ordering work smarter during a dump/restore?


This is fixed in CVS tip's pg_dump. You could probably get away with
using the development pg_dump with a 7.4 server --- I don't think we've
introduced any incompatibilities yet. If you're running something older
than 7.4, though, you'll have to keep hacking the dump order.

pg_restore has some options for fixing the order at reload time, which
would be your best bet if the schema is large.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sugapablo | last post by:
Tried googling, but I guess I have the wrong terminology for MS products. Using PostgreSQL, or MySQL, if I wanted to tranfer a database from one machine to another, I'd do a "dump" with a single...
3
by: Andrei Ivanov | last post by:
Hello, I have a dump created with pg_dump ver 7.4.1 from a postgres 7.4 database, with encoding SQL_ASCII. I'm trying to import this dump in a 7.4.1 postgres database with encoding UNICODE, but...
7
by: Cyril VELTER | last post by:
I'm trying to dump a database from a 7.1.3 server to a 7.4.2 one. It doesn't works because of difference in COPY format (unless I use -d which is VERY slow on a 16G database). What are the...
6
by: Együd Csaba | last post by:
Hi All, I'd like to dump out my database using plain text format. Everything is ok, but the bytea filds. Restoring the dump file (using <<psql -f LO_TRY_INSERT_BYTEA.sql tmp7>>) it sends an...
6
by: Soeren Gerlach | last post by:
Hi, some weeks ago I started to develop an application using Postgresql the first time. I'm running 7.4.3 on a Linux box with a plain 2.6.7 kernel, the storage is handled by 5 SATA disks,...
5
by: Chris Stankevitz | last post by:
My app reliably dies after a long time. I would like to dump core before it dies, and use that core as a starting point in debugging to save me from having to spend so much time waiting. Is...
1
by: ntech | last post by:
Hello, i am facing a problem. I am using postgresql database in Linux. After taking the dump of any postgresql database, when i restore the dump file into a new database, i dont get any oids. so can...
0
by: bogie | last post by:
Hello every one, I have a problem to restore my postgresql dumpfile. I have a postgresql database 7.3.2 in a linux environment and i want to restore the dumpfile that i make from linux environment...
2
by: clearissues | last post by:
Hi All, I have a python script which takes dump of postgres and restores the same. When i take a dump there is no problem. command to take dump: pg_dump -b -c -C --format=c -d -h <<hostname>>...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.