psql

Split a big postgres table into multiple csv

旧巷老猫 提交于 2020-02-24 06:49:50
问题 I am using following psql query to connect to a remote host and split a big table into multiple csv files. psql -h xx -p xx -U xx -d xx -c "\COPY (select * from table) TO program 'split --lines 1000' (format csv) I am not getting what mistake I am making here. 回答1: Have you tried using STDOUT ? $ psql -d db -c "COPY (SELECT * FROM t) TO STDOUT CSV " | split -1000 来源: https://stackoverflow.com/questions/60187391/split-a-big-postgres-table-into-multiple-csv

Error:must be owner of database

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-21 11:21:07
问题 I want to delete a particular database which I have named 'mysitedb' so what I did is I opened the terminal and entered the command 'dropdb mysitedb' then the error 'ERROR: must be owner of database mysitedb' pops up. I know the username and pass for the particular database but don't have a clue on deleting it. I am new to postgresql. be gentle :P 回答1: Q: I want to delete a particular database which I have named 'mysitedb' so what I did is I opened the terminal and entered the command 'dropdb

How to check all roles/user/group_role have what privileges in postgres database?

女生的网名这么多〃 提交于 2020-02-06 07:35:53
问题 I have postgres database. I want the list of users with access privileges they are being assigned. I tried to find query and also looked in to psql command line help. (\nu and all) but I haven't found any usefull information. Is anyone knows about that can help me out. Thanks. 回答1: There are few basic command like \du and \l that will provide the general information. For getting the detailed information you may use the below function. CREATE OR REPLACE FUNCTION database_privs(text) RETURNS

Why does psql not recognise my single quotes?

陌路散爱 提交于 2020-01-30 08:17:04
问题 $ psql -E --host=xxx --port=yyy --username=chi --dbname=C_DB -c 'DELETE FROM "Stock_Profile" WHERE "Symbol" = 'MSFT'; ' ERROR: column "msft" does not exist LINE 1: DELETE FROM "Stock_Profile" WHERE "Symbol" = MSFT; How do I show psql that MSFT is a string? It does not like 'MSFT', \'MSFT\' or ''MSFT'' 回答1: The problem you have is that you've run out of types of quote mark to nest; breaking apart, we have: your shell needs to pass a single string to the psql command; this can be either single

How to get out of a select in PostgreSQL without exiting to the terminal?

喜夏-厌秋 提交于 2020-01-30 07:51:47
问题 As you see in the image I have listed all the tables in a database... I can move up and down, but how can I get back to the postgres prompt? If I use CONTROL+X it takes me back to the linux prompt, but out of postgres. Thank you ALL for your patience with non-programmers! 回答1: It's less pager, simply type q . 回答2: https://www.postgresql.org/docs/current/static/app-psql.html If the environment variable PAGER is set, the output is piped to the specified program. Otherwise a platform-dependent

Python backed SQL Database returning a psycopg2.ProgrammingError: relation does not exist error when attempting to delete the data within a table?

我怕爱的太早我们不能终老 提交于 2020-01-26 04:31:14
问题 Intro: I have been working on building a Python backed PostgreSQL database of a Swiss style tournament using Vagrant running a Ubuntu VM for my Relational Database course in Udacity. Question: Why does it say the table does not exist when I attempt to delete the information within the existing table? I did a generic search to research psycopg2.ProgrammingError , but the information is mostly specific to other circumstances, and I was unable to make logical connections that would allow me fix

how to add database in a new cluster in postgreSQL?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-25 10:20:31
问题 I am using sudo pg_createcluster -u=$USER --datadir=candisDatabase -l=candisDatabase/candis.psql.log 9.6 candisCluster to create a new database cluster with the specified directory as candisDatabase under the account $USER (which is 'rupav'). pg_lsclusters Ver Cluster Port Status Owner Data directory Log file 9.6 candisCluster2 5433 online rupav candisDatabase candisDatabase/candis.psql.log 9.6 main 5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log

How do I pass subshell results (array) to an SSH command?

三世轮回 提交于 2020-01-23 17:15:25
问题 Trying it this way: #!/bin/bash myvals=`psql -d mydb -c "select id from table1 where 't'"` ssh user1@host1.domain.tld "for i in $myvals; do echo \$i >> values; done" As long as psql returns just one value, it works fine. But if its several values, I receive this response: bash: -c: line 1: syntax error near unexpected token `2' bash: -c: line 1: `2' Also, I tried to: myvals='1 2 3' And then it works fine: the values 1 2 3 are appended to the "values" file on the remote host; no error mesages.

Is there a way to set the max width of a column when displaying query results in psql?

你。 提交于 2020-01-22 17:19:45
问题 The problem I'm having is that I have a table with 10 columns. 1 of those columns is HTML and, as a result, is really long. It's so long that it wraps around several lines and screws up the otherwise useful output. Normally, I've been selecting all of the columns except for that one. However, I'm starting to join with another table and have like 20 columns now. Is there a way to specify the maximum column width or to truncate a column after a certain number of characters? I tried \x . It kind

Unable to restore psql database from pg_dump with a different username

廉价感情. 提交于 2020-01-21 11:49:10
问题 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