Questions tagged [bash]
The bash tag has no usage guidance.
25
questions
0
votes
1
answer
91
views
Issues using a psql -v variable with jsonb_set
Pretty obscure situation and a couple hours of trying different things with no luck.
I have a bash script which restores a production database backup locally. Part of the script runs some SQL to set ...
0
votes
0
answers
122
views
Escape single quotes when passing command to psql -c
I need to run the following command in a BASH shell:
sudo -u postgres /usr/pgsql-15/bin/psql -c "select count(*) from web_site where web_page like '%something%' " -d 'some_database'
The ...
0
votes
2
answers
163
views
Command line command to read Oracle Database export Success Message In log File
We have several oracle 19c servers with daily exports. I would like to find a way to run a command to read the export log file to find the success message for the day. e.g. I would like to putty into ...
0
votes
0
answers
15
views
What database my applications will use if I have a locally installed database beside it's pod running on local Kubernetes?
I have installed mysql on my Ubuntu machine. I also have a locally running Kubernetes and deployed a mysql deployment on Kubernetes and can reach to that using kubectl exec -it mysql-b4769786-5hf4m sh ...
2
votes
1
answer
6k
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
1
answer
2k
views
I get the error "(psycopg2.OperationalError) FATAL: role "wsb" does not exist", but the user does exits
I am trying connect to my postgress database using SQLAlchemy. I was working fine yesterday (01/27/22). Now I get the following error:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) ...
1
vote
1
answer
5k
views
Postgres how do return a message if no results for SELECT query
Have been trying to work out how to return a message if the result is empty.
I am running a select statement as below:
select * from maxIDValue where max_value > 1000000 order by max_value desc;
I ...
1
vote
1
answer
1k
views
How to return values from psql to bash with custom session settings
I need to set the datestyle to "dd/mm/yyyy" before calling a procedure and getting it's return value back to bash.
I tried the following:
read return <<< $(psql \
-...
2
votes
2
answers
1k
views
pg_dump hangs in Git Bash but works in Windows command line
I tried to make a backup of a database from Git Bash environment, but the executable does not output anything.
If I specify the filename using the -f flag, a blank file gets created, so the executable ...
0
votes
2
answers
365
views
Connecting to multiple Oracle databases hosted on different machines - Username as common and different password for each database
Environment:
We have ~100 databases hosted on multiple machines. All databases have common username but password is different on every database.
Issue:
How can I read the password and TNS (Service ...
0
votes
0
answers
772
views
Dump all data to json files
I'm working on a script that has to dump app data from a schema to json files. Here is what I have thus far:
export SCHEMA="citydb"
export DB="kv_db"
export PGPASSWORD=root
psql -...
2
votes
1
answer
790
views
execute mysqlshell from within a bash script? is it possible?
I am writing a backup script for a database and want to use mysqlshell util.dumpSchemas() utility.
But how on earth can I make it work from within a shell script?
The basic process I have is this:
...
0
votes
1
answer
31
views
Merging one SQL database into another
Currently in my CI I'm completely wiping production db with development db. That was fine for testing but I'm coming to a stage where I need to start merging instead of completely wiping.
Right now ...
0
votes
0
answers
2k
views
Local Postgres Server on Mac Pw Auth Fail
Disclaimer: I am new to MacOs. Haven't found any useful related question.
After successfully installing postgresql 13.2 via homebrew on MacOs 11.2.1 (BigSur) i run into the following problem:
Use ...
7
votes
1
answer
6k
views
How to pass environment variables to a sql file from bash shell (PostgreSQL)
I need to be able to pass environment variables, from a bash shell executing a .sql file using psql.
The psql command I am running is:
su postgres -c "psql -v ON_ERROR_STOP=1 -v dbname=example -v ...
1
vote
1
answer
2k
views
Save output of a Mongo Command to a Variable bash script
I have been writing a script to find and kill slow mongodb queries, how can I store output of db.currentOp() in a variable?
current I am using this but failing
#! /bin/bash
out=""
mongo <...
1
vote
0
answers
763
views
How to simulate slow queries on MongoDB
I need to write a shell script that finds and kills long running mongodb queries, but I don't have access to the database that runs slow queries, how to I simulate running slow queries on my local ...
2
votes
1
answer
496
views
Why does Postgresql Data directory revert to default after updates/reboots?
I have something that is pretty simple to explain. We have certain server builds as it relates to directories in our CentOS boxes at my company and so to accommodate those, I have a script that ...
0
votes
1
answer
357
views
Insert file content (with white line and special characters ) in bash variable for insert in oracle table with sqlplus
I write this simpe test.ksh scipt:
#!/bin/ksh
TEST=$(cat $1 )
sqlplus -S *****/*****@*****<<- EOF
set define off;
SET SQLBLANKLINES ON;
INSERT INTO DBADOC.TEST
(
"TEST"
)
...
0
votes
0
answers
1k
views
Bash Script Can't Connect to Azure Postgres using ENV Vars - "The Username should be in <username@hostname> format"
I have a bash script that exports ENV vars to use in connecting to an Azure Postgres DB (mydb.postgres.database.azure.com). For the user portion of that specifically it looks like this:
export PGUSER=&...
2
votes
2
answers
2k
views
Could not find a "psql" to execute
I have a bash script that run on a Linux (AWS Centos) server. There's an odd, but annoying warning message that pops up in the stdout whenever the script executes psql: could not find a "psql&...
0
votes
1
answer
230
views
Retreive the list of Up/Down status of Oracle database using Shell Script
I am trying to create a shell script for retrieving the list of Oracle database with status UP/DOWN.
0
votes
1
answer
125
views
How to quote a SQL*Plus identifier in a bash script?
I get "ORA-00904: "MEMORY_TARGET": invalid identifier" no matter how I try to quote the identifier in the following command:
MEMORY_TARGET=$(su - orat01 -c " echo 'select ...
5
votes
5
answers
26k
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
2
answers
584
views
Show full detail error message on the console
I try to get the error from this call:
$ psql --dbname=synapse -c "SELECT (json::JSONB->>'content')::JSONB->>'name' AS channel_name, json::JSONB->>'room_id' AS room_id, ...