I am trying to copy a table planet_osm_polygon
from one database osm
to another test
. I su postgres
and performed the pg_dump
.
Problem: However I'm getting the error could not change directory to "/root"
and the Password:
prompt appeared twice! Is there a way to perform the pg_dump
when logged in as root
?
root@lalaland:~# su postgres
postgres@lalaland:/root$ pg_dump -h localhost "osm" --table "public.planet_osm_polygon" |
psql -h localhost "test" --table "staging.planet_osm_polygon"
could not change directory to "/root"
could not change directory to "/root"
Password: Password:
UPDATE
Problem #2: It appears that the table is copied into the public
schema even though I passed the flag --table="staging.planet_osm_polygon"
. Why isn't it copied to schema staging
?
2 Answers 2
Try this: Re: could not change directory to "/root":
Apparently you did "su postgres" from the root account, so you're still in root's home directory. It'd be better to do "su - postgres" to ensure you've acquired all of the postgres account's environment. Reading "man su" might help you out here.
-
Is it normal that its asking for the password twice? Typing the password a second time does not mask it.Nyxynyx– Nyxynyx2013年04月18日 11:54:19 +00:00Commented Apr 18, 2013 at 11:54
-
1Maybe because you are doing two operations: 1. pg_dump -h localhost "osm" --table "public.planet_osm_polygon" 2. psql -h localhost "test" --table "staging.planet_osm_polygon"Ela– Ela2013年04月18日 12:07:01 +00:00Commented Apr 18, 2013 at 12:07
-
6Alternative with sudo: sudo -Hiu postgresMax Lobur– Max Lobur2016年09月19日 20:17:58 +00:00Commented Sep 19, 2016 at 20:17
-
Yeah, I probably should finally read over man su / sudo carefully...Brian Peterson– Brian Peterson2021年01月25日 16:13:48 +00:00Commented Jan 25, 2021 at 16:13
For me this did the trick, pay attention to quotes (')
sudo -Hiu postgres 'pg_dump --column-inserts --data-only --table=someTable entities_db > /var/backups/anywhere/$(date +%Y%m%d_%H%M%S)_someTable.sql'
Note the -Hiu
for sudo, or use su - postgres
you can also put that in a cronjob for root with crontab -e
-
great! I guess -hu would suffice, explanation here: explainshell.com/explain?cmd=sudo+-Hiurubo77– rubo772020年04月09日 18:28:45 +00:00Commented Apr 9, 2020 at 18:28
-
No, -H sets HOME env var and -i changes to that directory, so -iu works for me.Ev Dolzhenko– Ev Dolzhenko2024年02月27日 14:38:40 +00:00Commented Feb 27, 2024 at 14:38
psql
, that may be the cause of problem #2pg_dump
, is that actually callingpsql
? postgresql.org/docs/9.1/static/app-pgdump.htmlpsql -h localhost "test" --table "staging.planet_osm_polygon"
public
schema then