All Questions
11 questions
1
vote
1
answer
493
views
Set 'timing on' for the duration of the current `psql` session using command-line options
What is the equivalent of \timing on command in psql, using the psql command-line options? I am aware that this will enable timing for all psql sessions:
echo '\\timing on' >> ~/.psqlrc
I am ...
2
votes
1
answer
9k
views
Run PSQL command from bash script
I would like to know how to run \du within a script, and output that to a file.
Something like the following:
# some_script.sh
psql <database connection> & \du > output_of_du.txt
I can ...
0
votes
2
answers
59
views
How to query 30k of entries from an external data source by script
I have a SQL query which works for single checks:
SELECT trans_id from schema.table where trans_id like '%<trans_id>%'
There're might be better approaches to query for, but that's not the point.
...
0
votes
1
answer
3k
views
How to use psql command with no password prompt? [duplicate]
I'm trying to write shell script to avoid entering password every time while login to psql.
6
votes
5
answers
34k
views
What does "psql: /usr/pgsql-11/lib/libpq.so.5: no version information available (required by psql)" actually mean?
I have a question regarding following output:
[nikola@192 ~] $ sudo su - postgres
[postgres@192 ~] $ psql dvdrental postgres
psql: /usr/pgsql-11/lib/libpq.so.5: no version information available (...
0
votes
1
answer
2k
views
Shell script - psql run multiple statements from a variable one by one in one transaction
Im preparing a shell script to generate analyze command and all the commands will go to a variable.
echo $analyze_query
analyze tbl1;
analyze tbl2;
analyze tbl3;
Now I want to run one by one, and ...
2
votes
3
answers
9k
views
Use psql --set variable in a function
I want to create a script that will create some custom named schema and within it some tables and functions. Like this:
The example.sh file:
#!/bin/bash
# this is the only place I want to set the ...
2
votes
2
answers
2k
views
Running a command in psql `-c` that requires identifier quoting
I have created a database schema as "mytest.us" and inside this schema, I have created a table "a.b.c".
When I do
select * from "mytest.us"."a.b.c";
year | mydata
------+--------
2011 | test1
...
0
votes
1
answer
459
views
dynamic postgres inside shell script not working
PG_CMD="psql -d portal -U portal -c "
PG_CMD_TP="psql -d portal -U portal -t -P format=unaligned -c "
abc()
{
$PG_CMD "
DO \$$
BEGIN
select * from customer;
...
10
votes
2
answers
4k
views
Variable substitution in psql when using \copy
I'm using the psql command \copy and I would like to pass a variable to it from the shell (for table name) like I've done when scripting queries. I've read in the documentation for psql that:
The ...
7
votes
1
answer
22k
views
Drop multiple databases in one script
I am trying to figure out how to drop multiple databases on PostgreSQL in one sql script. I preferably need it to work both when executed in pgAdmin console, and when used in psql command line tool. ...