Error when loading sql file in postgres db using psql - schema already exists error - psql

Error - ERROR: schema "public" already exists when running psql to load a sql dump file into database.
PGPASSWORD=xyzabc pg_dump -U postgres -h cloudsql-proxy -p 3306 -d development -n public --format=p >/dev-db/devBackup.sql
export PGPASSWORD=postgres
psql -U postgres -h local-dev-db -p 5432 --dbname pangea_local_dev -c 'CREATE EXTENSION IF NOT EXISTS citext with schema public;'
psql -U postgres -h local-dev-db -p 5432 pangea_local_dev -1 -n public -f /dev-db/devBackup.sql

Related

Below is the command i have to convert from ISQL to PSQL

Below is ISQL query, which has column width -w and column seperator -s option can someone help with psql query for the same?
isql -U$username -P$PASSWORD -S$server -i/tmp/abc **-s~ -w500** > /tmp/xyz
psql -U $username -h $server -p $PORT -w -f /tmp/abc > /tmp/xyz
This shall be psql query but not sure about option -s and -w.

How to mongoimport in a remote server (Authentication error)

With this code I tried to get json data on remote ubuntu server.
mongoimport --port 27017 -d dbtest -c shops --file myfile.json --jsonArray
but I only got an error.
Failed: (Unauthorized) command insert requires authentication
I tried another codes but I can't authenticate... It only works on localhost.
How can I solve this?
I solve It!
mongoimport -u username -p 'password' --port 27017 -d dbtest -c shops --file myfile.json --jsonArray --authenticationDatabase admin

PG could not connect to server when trying to install postgresql on Manjaro

I tried to install postgresql on Linux Manjaro and create db and user.
I have executed next commands:
$ sudo pacman -S postgresql postgis
$ sudo -u postgres -i
Than
$ initdb -D '/var/lib/postgres/data'
returns 'access denied' error.
I was trying to create connection via pgAdmin4.
Than I got next error:
createuser: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I found a lot of similar issues. So tried some solves like changing the path of db location or reinstall postgresql.
My aim is to run pg in Rails. But now I have
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/run/postgresql/.s.PGSQL.5432"
when I am trying to execute
$ rails db:create
Seems, I do not understand the whole way of pg configuring. Thank you!
UPDATED:
Next commands solved the problem:
sudo pacman -R postgresql
sudo pacman -S postgresql postgis
sudo su - postgres -c "initdb -E UTF8 -D '/var/lib/postgres/data'"
systemctl start postgresql
systemctl status postgresql
sudo su - postgres
createuser user1
createdb -O user1 db1
psql db1 -U user1
Next commands solved the problem:
sudo pacman -R postgresql
sudo pacman -S postgresql postgis
sudo su - postgres -c "initdb -E UTF8 -D '/var/lib/postgres/data'"
systemctl start postgresql
systemctl status postgresql
sudo su - postgres
createuser user1
createdb -O user1 db1
psql db1 -U user1

how set password for password odoo secret in file?

i run container postgres and odoo container in linux system by docker, the problem is how to set password for odoo secret like in postgres :
$ echo 'secret' > notpasswords
$ docker run -d --name pg -e POSTGRES_PASSWORD_FILE=/notpasswords -v "$PWD/notpasswords:/notpasswords" postgres:9.6-alpine
$ docker run -it --rm --link pg postgres:9.6 bash
root#c37d1f3f2910:/# psql -h pg -U postgres
Password for user postgres:
psql (9.6.5)
Type "help" for help.
postgres=#
If you are planning to use this in a production environment, you should take a look at docker secrets. In this case, you can make use of a special postgres environment variable to refer to the postgres password (POSTGRES_PASSWORD_FILE).
$ docker run --name some-postgres -e POSTGRES_PASSWORD_FILE=/run/secrets/postgres-passwd -d postgres

Error when running a batch file in psql (using -f but not with <)

My command prompt has the following structure:
psql -d databasename -h hostname -p portnumber -U username -w -f batchfile\location\here
I get the following error:
ERROR: syntax error at or near "ï>>¿"
LINE 1: ï>>¿
This causes the first sql query in the batch to not run.
I don't seem to have any problems when executing a batch file using <. See example below:
psql -d databasename -h hostname -p portnumber -U username -w < batchfile\location\here
I'm running postgreSQL version 8.2.15.
Is there something in the command line or the sql batch that I need when using -f? Thanks in advance!

Resources