psql

Unable to restore psql database from pg_dump with a different username

橙三吉。 提交于 2020-01-21 11:49:09
问题 I need to dump a postgres database from computer1 with postgres username1 and then restore it on computer2 with postgres username2. I keep running into the error that looks like the backup file wants to use username1: When I run this on computer2: psql dbname < backupname.pgsql I get this error: ERROR: role "username1" does not exist I have tried: // Dumping from computer1: pg_dump dbname > backupname.sql pg_dump dbname > backupname.pgsql pg_dump -U username1 dbname -N topology -T spacial_ref

Deleting records from a remote postgresql database using locally supplied list

纵然是瞬间 提交于 2020-01-20 08:33:00
问题 I have the following logic in a bash script that works: #copy records to delete file to respective servers. faster than running locally scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $dir/$server.records_to_delete.txt $server:/tmp/ # trigger the deletion on remote machine. deletion_status=$(psql -U test testdb -h $server -c "CREATE TEMP TABLE tmp_cdr (id int); COPY tmp_widgets FROM '/tmp/$server.records_to_delete.txt'; DELETE FROM widgets USING tmp_cdr WHERE widgets.id = tmp

Deleting records from a remote postgresql database using locally supplied list

ぃ、小莉子 提交于 2020-01-20 08:32:24
问题 I have the following logic in a bash script that works: #copy records to delete file to respective servers. faster than running locally scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $dir/$server.records_to_delete.txt $server:/tmp/ # trigger the deletion on remote machine. deletion_status=$(psql -U test testdb -h $server -c "CREATE TEMP TABLE tmp_cdr (id int); COPY tmp_widgets FROM '/tmp/$server.records_to_delete.txt'; DELETE FROM widgets USING tmp_cdr WHERE widgets.id = tmp

Use pg_restore to restore from a newer version of PostgreSQL

爷,独闯天下 提交于 2020-01-20 03:28:11
问题 I have a (production) DB server running PostgreSQL v9.0 and a development machine running PostgreSQL v8.4. I would like to take a dump of the production DB and use it on the development machine. I cannot upgrade the postgres on the dev machine. On the production machine, I run: pg_dump -f nvdls.db -F p -U nvdladmin nvdlstats On the development machine, I run: pg_restore -d nvdlstats -U nvdladmin nvdls.db And I got this error: pg_restore: [archiver] unsupported version (1.12) in file header

Use pg_restore to restore from a newer version of PostgreSQL

眉间皱痕 提交于 2020-01-20 03:28:04
问题 I have a (production) DB server running PostgreSQL v9.0 and a development machine running PostgreSQL v8.4. I would like to take a dump of the production DB and use it on the development machine. I cannot upgrade the postgres on the dev machine. On the production machine, I run: pg_dump -f nvdls.db -F p -U nvdladmin nvdlstats On the development machine, I run: pg_restore -d nvdlstats -U nvdladmin nvdls.db And I got this error: pg_restore: [archiver] unsupported version (1.12) in file header

PSQL - Select size of tables for both partitioned and normal

帅比萌擦擦* 提交于 2020-01-17 04:54:51
问题 Thanks in advance for any help with this, it is highly appreciated. So, basically, I have a Greenplum database and I am wanting to select the table size for the top 10 largest tables. This isn't a problem using the below: select sotaidschemaname schema_name ,sotaidtablename table_name ,pg_size_pretty(sotaidtablesize) table_size from gp_toolkit.gp_size_of_table_and_indexes_disk order by 3 desc limit 10 ; However I have several partitioned tables in my database and these show up with the above

Can't find my databases after power cut and reboot

给你一囗甜甜゛ 提交于 2020-01-16 05:37:06
问题 OSX 10.9.3 psql 9.3.4 I had several database that I was working on and we had a power cut over night. Now non of my database (including the default database (username)) are present. Why have all the database gone from psql? Wouldn't they have been saved? Is there any possibly that they are still present but not listed by \dt? Any help on how to recover these databases will be greatly appreciated! 回答1: A power cut can only cause database corruption or loss if the underlying storage is unsafe -

Error connecting to heroku postgres db in nodejs

时光总嘲笑我的痴心妄想 提交于 2020-01-14 12:53:09
问题 It seems after my database was upgraded to 10.2 I'm unable to connect. I'm using the pg 7.4.2 npm package. To be clear, I have been connecting without issue for 6 months using the same connection string which had ?ssl=true appended to it. I get this error connecting via Pool or Client. AssertionError [ERR_ASSERTION]: false == true at Object.exports.connect (_tls_wrap.js:1099:3) at Socket.<anonymous> (/home/e/express/testpg/node_modules/pg/lib/connection.js:94:23) at Object.onceWrapper (events

How to get definition/source code of an aggregate in PostgreSQL?

浪尽此生 提交于 2020-01-13 11:34:00
问题 I found this related answer useful: Export "Create Aggregate" functions from PostgreSQL But how do I get the CREATE AGGREGATE statement without a GUI client (e.g. with psql command line)? 回答1: Something like this, but I'm not sure if this covers all possible ways of creating an aggregate (it definitely does not take the need for quoted identifiers into account) SELECT 'create aggregate '||n.nspname||'.'||p.proname||'('||format_type(a.aggtranstype, null)||') (sfunc = '||a.aggtransfn ||', stype

How to get definition/source code of an aggregate in PostgreSQL?

[亡魂溺海] 提交于 2020-01-13 11:32:11
问题 I found this related answer useful: Export "Create Aggregate" functions from PostgreSQL But how do I get the CREATE AGGREGATE statement without a GUI client (e.g. with psql command line)? 回答1: Something like this, but I'm not sure if this covers all possible ways of creating an aggregate (it definitely does not take the need for quoted identifiers into account) SELECT 'create aggregate '||n.nspname||'.'||p.proname||'('||format_type(a.aggtranstype, null)||') (sfunc = '||a.aggtransfn ||', stype