psql

psql: FATAL: too many connections for role

浪尽此生 提交于 2019-11-30 19:39:01
I tried connecting to the database server using the command: psql -h host_ip -d db_name -U user_name --password It displays the following line and refuses to connect. psql: FATAL: too many connections for role "user_name". How to close the active connections? I do not have admin rights for the database. I am just an ordinary user. From inside any DB of the cluster: Catch 22: you need to be connected to a database first. Maybe you can connect as another user? To get detailed information for each connection by this user: SELECT * FROM pg_stat_activity WHERE usename = 'user_name'; As the same

Use psql's \\copy for a multi-line query

不打扰是莪最后的温柔 提交于 2019-11-30 07:59:24
This is a follow-up question from this answer for " Save PL/pgSQL output from PostgreSQL to a CSV file ". I need to write a client-side CSV file using psql's \copy command . A one liner works: db=> \copy (select 1 AS foo) to 'bar.csv' csv header COPY 1 However, I have long queries that span several lines. I don't need to show the query, as I can't seem to extend this past one line without a parse error: db=> \copy ( \copy: parse error at end of line db=> \copy ( \\ \copy: parse error at end of line db=> \copy (" \copy: parse error at end of line db=> \copy "( \copy: parse error at end of line

Postgresql COPY empty string as NULL not work

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 07:51:56
问题 I have a CSV file with some integer column, now it 's saved as "" (empty string). I want to COPY them to a table as NULL value. With JAVA code, I have try these: String sql = "COPY " + tableName + " FROM STDIN (FORMAT csv,DELIMITER ',', HEADER true)"; String sql = "COPY " + tableName + " FROM STDIN (FORMAT csv,DELIMITER ',', NULL '' HEADER true)"; I get: PSQLException: ERROR: invalid input syntax for type numeric: "" String sql = "COPY " + tableName + " FROM STDIN (FORMAT csv,DELIMITER ',',

PostgreSQL Nested JSON Querying

烈酒焚心 提交于 2019-11-30 06:53:19
问题 On PostgreSQL 9.3.4, I have a JSON type column called "person" and the data stored in it is in the format {dogs: [{breed: <>, name: <>}, {breed: <>, name: <>}]} . I want to retrieve the breed of dog at index 0. Here are the two queries I ran: Doesn't work db=> select person->'dogs'->>0->'breed' from people where id = 77; ERROR: operator does not exist: text -> unknown LINE 1: select person->'dogs'->>0->'bree... ^ HINT: No operator matches the given name and argument type(s). You might need to

psql: FATAL: too many connections for role

梦想与她 提交于 2019-11-30 03:09:41
问题 I tried connecting to the database server using the command: psql -h host_ip -d db_name -U user_name --password It displays the following line and refuses to connect. psql: FATAL: too many connections for role "user_name". How to close the active connections? I do not have admin rights for the database. I am just an ordinary user. 回答1: From inside any DB of the cluster: Catch 22: you need to be connected to a database first. Maybe you can connect as another user? To get detailed information

Postgresql -bash: psql: command not found

放肆的年华 提交于 2019-11-29 23:51:52
I have installed PostgreSQL and it is working ok. However, when I went to restore a backup I got the error -bash: psql: command not found : [root@server1 ~]# su postgres [postgres@server1 root]$ psql -f all.sql bash: psql: command not found [postgres@server1 root]$ What have I done wrong? marto perhaps psql isn't in the PATH of the postgres user. Use the locate command to find where psql is and ensure that it's path is in the PATH for the postgres user. Pavel export PATH=/usr/pgsql-9.2/bin:$PATH The program executable psql is in the directory /usr/pgsql-9.2/bin , and that directory is not

How to Add, Delete new Columns in Sequelize CLI

≡放荡痞女 提交于 2019-11-29 22:19:27
I've just started using Sequelize and Sequelize CLI Since it's a development time, there are a frequent addition and deletion of columns. What the best the method to add a new column to an existing model? For example, I want to a new column ' completed ' to Todo model. I'll add this column to models/todo.js. Whats the next step? I tried sequelize db:migrate not working: "No migrations were executed, database schema was already up to date." Maria Ines Parnisari If you are using sequelize-cli you need to create the migration first. This is just a file that tells the engine how to update the

Forgot Admin Password on Postgres (Windows Installation), can't reset

☆樱花仙子☆ 提交于 2019-11-29 18:37:32
问题 I have a Windows PostgreSQL installation. According to some posts, there is no default password set for the 'postgres' user yet I can't connect using an empty password string. I'm receiving this exception when I try to connect: Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres" The most relevant tip was this: https://stackoverflow.com/a/25943227/1005607 Open pg_hba.conf Change md5 -> TRUST then restart PgAdmin. I tried that and restarted

Deleting records from a remote postgresql database using locally supplied list

落爺英雄遲暮 提交于 2019-11-29 16:12:16
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_widgets.id;") But I'm trying to consolidate into one command. So instead of scp'ing the list of records

Why psql can't find relation name for existing table?

扶醉桌前 提交于 2019-11-29 16:07:18
问题 Here' my current state. Eonil=# \d+ List of relations Schema | Name | Type | Owner | Size | Description --------+------------+-------+-------+------------+------------- public | TestTable1 | table | Eonil | 8192 bytes | (1 row) Eonil=# \d+ TestTable1 Did not find any relation named "TestTable1". Eonil=# What is the problem and how can I see the table definition? 回答1: Postgres psql needs escaping for capital letters. Eonil=# \d+ "TestTable1" So this works well. Eonil=# \d+ "TestTable1" Table