473,395 Members | 1,937 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,395 software developers and data experts.

copy a database

Hi!

Is it possible to copy/migrate one database from one postgres server to
other copying just the files in /var/lib/postgres/data/ ?

I can't use pg_dump because it give me an error. I think than the
instalation of postgres is corrupt because it give me a lot of error
like "ERROR: relation "pg_catalog.pg_user" does not exist".

Thanks,

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

Nov 23 '05 #1
14 5722
In an attempt to throw the authorities off his trail, ds****@xsto.info (David Suela Fernández) transmitted:
Is it possible to copy/migrate one database from one postgres server to
other copying just the files in /var/lib/postgres/data/ ?

I can't use pg_dump because it give me an error. I think than the
instalation of postgres is corrupt because it give me a lot of error
like "ERROR: relation "pg_catalog.pg_user" does not exist".


Copying files from a corrupted database will just get you a _second_
corrupt database.

If it's corrupted, then the best you can do is to get what data you
can out of the database, and put it into a NEW database.

What you might try would be to dump it table by table:

for table in this_table that_table other_table; do
pg_dump -p $SOURCEPORT -t $table $SOURCEDB | psql -p $NEWPORT $NEWDB
done

If the database is corrupted, that's likely to partly break, but I
doubt you'll do much better any other way.
--
If this was helpful, <http://svcs.affero.net/rm.php?r=cbbrowne> rate me
http://cbbrowne.com/info/lisp.html
"Natives who beat drums to drive off evil spirits are objects of scorn
to smart Americans who blow horns to break up traffic jams."
-- Unknown
Nov 23 '05 #2
El mié, 25-08-2004 a las 14:58, Christopher Browne escribió:
In an attempt to throw the authorities off his trail, ds****@xsto.info (David Suela Fernández) transmitted:
Is it possible to copy/migrate one database from one postgres server to
other copying just the files in /var/lib/postgres/data/ ?

I can't use pg_dump because it give me an error. I think than the
instalation of postgres is corrupt because it give me a lot of error
like "ERROR: relation "pg_catalog.pg_user" does not exist".


Copying files from a corrupted database will just get you a _second_
corrupt database.

If it's corrupted, then the best you can do is to get what data you
can out of the database, and put it into a NEW database.

What you might try would be to dump it table by table:

for table in this_table that_table other_table; do
pg_dump -p $SOURCEPORT -t $table $SOURCEDB | psql -p $NEWPORT $NEWDB
done


The problem is that pg_dump always give me the next error:

pg_dump: SQL command failed
pg_dump: Error message from server: ERROR: relation "pg_user" does not exist
pg_dump: The command was: SELECT (SELECT usename FROM pg_user WHERE usesysid = datdba) as dba, pg_encoding_to_char(encoding) as encoding, datpath FROM pg_database WHERE datname = 'ez3'

I have the db scheme (tables and basic data), but what i need is the new
data of the db. I can access the db and make queries.

I think i'll make a script to pass data from the corrupt database to the
new one.

--
David Suela Fernández <ds****@xsto.info>
xsto.info <el acceso a la información>
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #3
On Wed, 2004-08-25 at 15:08, David Suela Fernández wrote:
The problem is that pg_dump always give me the next error:

pg_dump: SQL command failed
pg_dump: Error message from server: ERROR: relation "pg_user" does not exist
pg_dump: The command was: SELECT (SELECT usename FROM pg_user WHERE usesysid = datdba) as dba, pg_encoding_to_char(encoding) as encoding, datpath FROM pg_database WHERE datname = 'ez3'


Maybe recreating pg_user in the database will help. It is a global
table, so if you have other databases where pg_user exists, copy the row
from pg_class in that database to pg_class in the corrupted database.

--
Oliver Elphick ol**@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"But the day of the Lord will come as a thief in the
night. The heavens shall pass away with a great noise,
and the elements shall melt with fervent heat, and the
earth and the works that are therein shall be burned
up." II Peter 3:10
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #4
On Wed, Aug 25, 2004 at 04:25:02PM +0100, Oliver Elphick wrote:
On Wed, 2004-08-25 at 15:08, David Suela Fernández wrote:
The problem is that pg_dump always give me the next error:

pg_dump: SQL command failed
pg_dump: Error message from server: ERROR: relation "pg_user" does not exist
pg_dump: The command was: SELECT (SELECT usename FROM pg_user WHERE
usesysid = datdba) as dba, pg_encoding_to_char(encoding) as
encoding, datpath FROM pg_database WHERE datname = 'ez3'


Maybe recreating pg_user in the database will help. It is a global
table, so if you have other databases where pg_user exists, copy the row
from pg_class in that database to pg_class in the corrupted database.


No, pg_user is a view on pg_shadow ...

SELECT pg_shadow.usename, pg_shadow.usesysid, pg_shadow.usecreatedb,
pg_shadow.usesuper, pg_shadow.usecatupd, '********'::text AS passwd,
pg_shadow.valuntil, pg_shadow.useconfig FROM pg_shadow;

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
Y una voz del caos me habló y me dijo
"Sonríe y sé feliz, podría ser peor".
Y sonreí. Y fui feliz.
Y fue peor.
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #5
On Wed, Aug 25, 2004 at 12:09:58PM -0400, Alvaro Herrera wrote:
No, pg_user is a view on pg_shadow ...

SELECT pg_shadow.usename, pg_shadow.usesysid, pg_shadow.usecreatedb,
pg_shadow.usesuper, pg_shadow.usecatupd, '********'::text AS passwd,
pg_shadow.valuntil, pg_shadow.useconfig FROM pg_shadow;


Sorry, this is obviously missing the

CREATE VIEW pg_user AS

part.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"The important things in the world are problems with society that we don't
understand at all. The machines will become more complicated but they won't
be more complicated than the societies that run them." (Freeman Dyson)
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #6
On Wed, 2004-08-25 at 17:09, Alvaro Herrera wrote:
On Wed, Aug 25, 2004 at 04:25:02PM +0100, Oliver Elphick wrote:

Maybe recreating pg_user in the database will help. It is a global
table, so if you have other databases where pg_user exists, copy the row
from pg_class in that database to pg_class in the corrupted database.


No, pg_user is a view on pg_shadow ...


Fingers! view ... table ... thingy

What I meant is that, since it is global, recreating the item in
pg_class as a copy of the entry in another database should possibly get
rid of the pg_dump problem. If you create a new view, the result will
presumably not be restorable.

--
Oliver Elphick ol**@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"But the day of the Lord will come as a thief in the
night. The heavens shall pass away with a great noise,
and the elements shall melt with fervent heat, and the
earth and the works that are therein shall be burned
up." II Peter 3:10
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #7
David Suela =?ISO-8859-1?Q?Fern=E1ndez?= <ds****@xsto.info> writes:
The problem is that pg_dump always give me the next error: pg_dump: SQL command failed
pg_dump: Error message from server: ERROR: relation "pg_user" does not exist


Have you tried re-creating that view?

CREATE VIEW pg_catalog.pg_user AS
SELECT
usename,
usesysid,
usecreatedb,
usesuper,
usecatupd,
'********'::text as passwd,
valuntil,
useconfig
FROM pg_shadow;

regards, tom lane

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

http://archives.postgresql.org

Nov 23 '05 #8
On Wed, Aug 25, 2004 at 05:57:35PM +0100, Oliver Elphick wrote:
On Wed, 2004-08-25 at 17:09, Alvaro Herrera wrote:
On Wed, Aug 25, 2004 at 04:25:02PM +0100, Oliver Elphick wrote:

Maybe recreating pg_user in the database will help. It is a global
table, so if you have other databases where pg_user exists, copy the row
from pg_class in that database to pg_class in the corrupted database.


No, pg_user is a view on pg_shadow ...


Fingers! view ... table ... thingy

What I meant is that, since it is global, recreating the item in
pg_class as a copy of the entry in another database should possibly get
rid of the pg_dump problem. If you create a new view, the result will
presumably not be restorable.


But pg_user is not global ...

alvherre=# select relname, relisshared from pg_class where relname = 'pg_user';
relname | relisshared
---------+-------------
pg_user | f
(1 fila)

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"No deja de ser humillante para una persona de ingenio saber
que no hay tonto que no le pueda enseñar algo." (Jean B. Say)
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #9
On Wed, 2004-08-25 at 20:08, Alvaro Herrera wrote:
On Wed, Aug 25, 2004 at 05:57:35PM +0100, Oliver Elphick wrote:
What I meant is that, since it is global,
.... But pg_user is not global ...


Yes; sorry, I was looking at the wrong thing.

--
Oliver Elphick ol**@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"But the day of the Lord will come as a thief in the
night. The heavens shall pass away with a great noise,
and the elements shall melt with fervent heat, and the
earth and the works that are therein shall be burned
up." II Peter 3:10
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #10
Have you tried pg_dump --no-owner in order to avoid getting the
ownership information?

David Suela Fernández wrote:
El mié, 25-08-2004 a las 14:58, Christopher Browne escribió:

In an attempt to throw the authorities off his trail, ds****@xsto.info (David Suela Fernández) transmitted:

Is it possible to copy/migrate one database from one postgres server to
other copying just the files in /var/lib/postgres/data/ ?

I can't use pg_dump because it give me an error. I think than the
instalation of postgres is corrupt because it give me a lot of error
like "ERROR: relation "pg_catalog.pg_user" does not exist".

Copying files from a corrupted database will just get you a _second_
corrupt database.

If it's corrupted, then the best you can do is to get what data you
can out of the database, and put it into a NEW database.

What you might try would be to dump it table by table:

for table in this_table that_table other_table; do
pg_dump -p $SOURCEPORT -t $table $SOURCEDB | psql -p $NEWPORT $NEWDB
done


The problem is that pg_dump always give me the next error:

pg_dump: SQL command failed
pg_dump: Error message from server: ERROR: relation "pg_user" does not exist
pg_dump: The command was: SELECT (SELECT usename FROM pg_user WHERE usesysid = datdba) as dba, pg_encoding_to_char(encoding) as encoding, datpath FROM pg_database WHERE datname = 'ez3'

I have the db scheme (tables and basic data), but what i need is the new
data of the db. I can access the db and make queries.

I think i'll make a script to pass data from the corrupt database to the
new one.


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

Nov 23 '05 #11
El mié, 25-08-2004 a las 20:54, Tom Lane escribió:
David Suela =?ISO-8859-1?Q?Fern=E1ndez?= <ds****@xsto.info> writes:
The problem is that pg_dump always give me the next error:

pg_dump: SQL command failed
pg_dump: Error message from server: ERROR: relation "pg_user" does notexist


Have you tried re-creating that view?

CREATE VIEW pg_catalog.pg_user AS
SELECT
usename,
usesysid,
usecreatedb,
usesuper,
usecatupd,
'********'::text as passwd,
valuntil,
useconfig
FROM pg_shadow;

regards, tom lane


It return:
ERROR: permission denied to create "pg_catalog.pg_user"
DETAIL: System catalog modifications are currently disallowed.

How can i change this permissions?

--
David Suela Fernández <ds****@xsto.info>
xsto.info <el acceso a la información>
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #12
David Suela =?ISO-8859-1?Q?Fern=E1ndez?= <ds****@xsto.info> writes:
It return:
ERROR: permission denied to create "pg_catalog.pg_user"
DETAIL: System catalog modifications are currently disallowed.
How can i change this permissions?


IIRC, you need to run a standalone backend, with either the -O or -P
switch (I forget which). The REINDEX man page has some tips about this.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #13
Have you tried to use "copy" to export the data from each table?

As a last resort you could try this, since you said you can still
select data from the tables.

Make a list of tables then :

sed -e "/^.*/copy & TO '&.sql';/" table.list | psql database

This should create a file for each table ending with ".sql".
Then re-create the table on the new DB and use "copy" to
import the data from the files.
David Suela Fernández wrote:
El mié, 25-08-2004 a las 20:54, Tom Lane escribió:

David Suela =?ISO-8859-1?Q?Fern=E1ndez?= <ds****@xsto.info> writes:

The problem is that pg_dump always give me the next error:
pg_dump: SQL command failed
pg_dump: Error message from server: ERROR: relation "pg_user" does not exist

Have you tried re-creating that view?

CREATE VIEW pg_catalog.pg_user AS
SELECT
usename,
usesysid,
usecreatedb,
usesuper,
usecatupd,
'********'::text as passwd,
valuntil,
useconfig
FROM pg_shadow;

regards, tom lane


It return:
ERROR: permission denied to create "pg_catalog.pg_user"
DETAIL: System catalog modifications are currently disallowed.

How can i change this permissions?

--
Guy Fraser

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #14

IIRC, you need to run a standalone backend, with either the -O or -P
switch (I forget which). The REINDEX man page has some tips about this.


I run a standalone backend and create the view. Now it works perfectly.

Thanks a lot !!!

--
David Suela Fernández <ds****@xsto.info>
xsto.info <el acceso a la información>
---------------------------(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 23 '05 #15

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

Similar topics

1
by: Catherine Jo Morgan | last post by:
I get the point of backing up the database I'm working on, but what's a prototype copy? How do I make one and why is it important to work on that rather than on the main database? Or is this more...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
1
by: Rachel McConnell | last post by:
Hi, I am trying to import data using COPY, from a file containing thirty or so COPY commands each with 0 or more rows of data. Reason, I have a small data set I want to include into a database...
4
by: JIM.H. | last post by:
Hello, I am trying to write the data I got from a web service to my table in SQL Server I need to append the dataset wsDS to the dataset ds and do update. PVS.myWS.Loader load = new...
5
by: Steve | last post by:
Hi; I thought I would rephrase a question I asked in another post to more quickly get to the heart of the matter. My apologies for anyone who is offended by what appears to be a repetition. ...
2
by: miroku800 | last post by:
A little history I designed a program in VB6 which used an access database with the aid of a then workmate (who has now moved on and lost interest) which was in two parts. A master program and a...
1
by: Scott Gifford | last post by:
Hello, I'm working on an providing an iterator interface to a database. The basic thing I'm trying to accomplish is to have my iterator read rows from the database and return constructed...
8
by: Abandoned | last post by:
Hi. I want to copy my database but python give me error when i use this command. cursor.execute("pg_dump mydata old.dump") What is the problem ? And how can i copy the database with python ?...
1
by: ll | last post by:
Hi, I have copied a MS SQL database to my local machine and am testing it with ASP pages, locally, on IIS. I have a db connect page that keeps the current connections for the live database. My...
1
by: Coni | last post by:
Hello, I am following steps to implement security on access 2003 through distribution: I have split the database and I am trying to distribute it: I have copied the back end file and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.