psql

psql: FATAL: role “vagrant” does not exist [duplicate]

ぃ、小莉子 提交于 2019-12-21 03:53:33
问题 This question already has answers here : PostgreSQL error: Fatal: role “username” does not exist (14 answers) Closed 5 years ago . I created a vagrant instance and I am getting this error every time I try and do psql in the terminal How would Fix it. the error is as states: psql: FATAL: role "vagrant" does not exist I thought vagrant takes care of this? This is my vagrant file: Vagrant.require_plugin "vagrant-omnibus" Vagrant.require_plugin "vagrant-berkshelf" Vagrant.configure(2) do |config|

Heroku rake db:migrate does not create tables (Rails 5)

不问归期 提交于 2019-12-20 05:42:06
问题 I have a Rails 5 app and I wanted to destroy and rebuild my live database (site not launched yet). So I followed the steps that should've worked (they used to work in the past): heroku pg:reset HEROKU_POSTGRESQL_HEROKUCOLOR_URL --confirm {app_name} heroku run rake db:migrate heroku run rake db:seed Steps 1 & 2 complete successfully and step 3 fails with the error ('adminsettings' is one of my tables): Running rake db:seed on {app_name}... starting, run.7198 (Hobby) Running rake db:seed on

Heroku rake db:migrate does not create tables (Rails 5)

浪尽此生 提交于 2019-12-20 05:41:40
问题 I have a Rails 5 app and I wanted to destroy and rebuild my live database (site not launched yet). So I followed the steps that should've worked (they used to work in the past): heroku pg:reset HEROKU_POSTGRESQL_HEROKUCOLOR_URL --confirm {app_name} heroku run rake db:migrate heroku run rake db:seed Steps 1 & 2 complete successfully and step 3 fails with the error ('adminsettings' is one of my tables): Running rake db:seed on {app_name}... starting, run.7198 (Hobby) Running rake db:seed on

How to display “invisible” unicode characters in psql / postgres?

本秂侑毒 提交于 2019-12-19 06:50:54
问题 How can I display normally invisible unicode characters from within psql (the postgres command line client)? 回答1: To see otherwise invisible Unicode in a postgress table, you'll want to use "encode" and "escape" both. And just for fun, the escape function requires a cast to type bytea. Putting it all together: # CREATE TABLE xxx_test (foo text); # INSERT INTO xxx_test (foo) values (E'Invis\u200eble €'); # SELECT foo from xxx_test; Invis‎ble € # SELECT encode(foo::bytea, 'escape') FROM xxx

Connecting to remote PostgreSQL database over SSH tunnel using Python

家住魔仙堡 提交于 2019-12-19 04:04:29
问题 I have a problem with connecting to a remote database using SSH tunnel (now I'm trying with Paramiko). Here is my code: #!/usr/bin/env python3 import psycopg2 import paramiko import time #ssh = paramiko.SSHClient() #ssh.load_system_host_keys() #ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #ssh.connect('pluton.kt.agh.edu.pl', 22, username='aburban', password='pass') t = paramiko.Transport(('pluton.kt.agh.edu.pl', 22)) t.connect(username="aburban", password='pass') c = paramiko

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

╄→гoц情女王★ 提交于 2019-12-18 12:46:15
问题 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

Show query result column types (PostgreSQL)

天涯浪子 提交于 2019-12-18 12:05:33
问题 Is there a way to easily get the column types of a query result? I read the psql documentation, but I don't think it supports that. Ideally, I'd be able to get something like: columna : text | columnb : integer ----------------+------------------- oh hai | 42 Is there a way I can get this information without coding something up? 回答1: I don't think you can print exactly what you have in the sample, unless you write a stored procedure for it. One way to do it (two "selects"): create table my

Postgresql -bash: psql: command not found

不问归期 提交于 2019-12-18 10:48:31
问题 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? 回答1: 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. 回答2: export PATH=/usr/pgsql-9.2/bin:

Accessing external XML files as variables in a PSQL script (sourced from a bash script)

旧城冷巷雨未停 提交于 2019-12-18 07:25:05
问题 Following this example, I am having trouble using a PostgreSQL variables in a *.sql script: I want to iterate over a number of XML data files, using a BASH script the BASH script assigns XML file names to a variable, that is passed to SQL script the SQL script, called by that BASH script, loads those data into PostgreSQL If I source the XML files directly, there is no problem; however, I cannot access that variable, in my SQL script: In my SQL script ( hmdb.sql ) I can access the PSQL

PL/pgSQL functions: How to return a normal table with multiple columns using an execute statement

一笑奈何 提交于 2019-12-17 17:45:11
问题 I've got this PL/pgSQL function which must return some users information. CREATE OR REPLACE FUNCTION my_function( user_id integer ) RETURNS TABLE( id integer, firstname character varying, lastname character varying ) AS $$ DECLARE ids character varying; BEGIN ids := ''; --Some code which build the ids string, not interesting for this issue RETURN QUERY EXECUTE 'SELECT users.id, users.firstname, users.lastname FROM public.users WHERE ids IN (' || ids || ')'; END; $$ LANGUAGE plpgsql; The