473,769 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_n ext_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"."accou nt" (
"acct_id" BIGSERIAL,
...,
"acct_pin_c ode" VARCHAR(16) NOT NULL DEFAULT get_next_pin_co de()
) 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_co de()
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 2564
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_n ext_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"."accou nt" (
"acct_id" BIGSERIAL,
...,
"acct_pin_c ode" VARCHAR(16) NOT NULL DEFAULT get_next_pin_co de()
) 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_co de()
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 YourEmailAddres sHere" to ma*******@postg resql.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 incompatibiliti es 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
41032
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 command, such as: mysqldump > Then I'd take the file generated and dump it back onto a new machine. What's the process with MS SQL Server? Can someone point me in the
3
6707
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 I'm getting some errors: psql:dump.sql:1277: ERROR: invalid memory alloc request size 1073741824 psql:dump.sql:3490: ERROR: invalid byte sequence for encoding
7
2057
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 difference between the 7.1.3 and 7.4.2 formats (seems to be related at least to newlines) ? Is it possible to modify the dump with a sed script to make it usable by 7.4.2 ? Thanks
6
3546
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 error message like psql:LO_TRY_INSERT_BYTEA.sql:14: ERROR: Bad input string for type bytea Trying dumping with copy commands it sends this error: psql:LO_TRY_COPY_BYTEA.sql:13: lost synchronization with server, resetting
6
11316
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, managed by a 3ware controller and using a xfs filesystem. The DB server is a 3 Ghz P4 with 4 Gig of Ram, so the machine is quite fast for most purposes I need it; the DB server is a pure DB server, theres no application running on it. I dump and...
5
2435
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 this possible? I suppose I could run my entire IDE inside a vmware virtual machine? Thanks for your help, Chris
1
3260
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 anyone help me in this issue? Does it happen due to version mismatch? how do i take the dump so that when i restore it, the oids are also available? Thanks, Ntech
0
3011
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 to the postgresql 8.1.11 in a window environment. I make my backup in a postgresql 7.3.2 in linux environment with the following command : pg_dump -b -v -Fc -Z9 -U _postgresql -f istpdb-2007-08-09.psqldump istpdb and i try to restore it in...
2
7340
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>> -p 5432 -U postuser -f /tmp/april_23/abc.sql abc Restore command: pg_restore -c --format=c -h <<hostname>> -p 5432 -U postuser -d sfdb /tmp/april_23/abc.sql
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.