Skip to navigation
Script to import a postgresql db
05.06.17
#!/bin/bash die () { echo >&2 "$@" exit 1 } if [ $# -eq 0 ] ; then die "example : ./import.sh 127.0.0.1 USER DATABASE" elif [ $# -eq 1 ] ; then die "example : ./import.sh 127.0.0.1 USER DATABASE" elif [ $# -eq 2 ] ; then die "example : ./import.sh 127.0.0.1 USER DATABASE" elif [ $# -eq 3 ] ; then SERVER=$1 USER=$2 DATABASE=$3 else die "usage : droptables server user database" fi echo "s:$SERVER u:$USER d:$DATABASE" #echo "127.0.0.1:*:*:$USER:PASSWORD" >> ~/.pgpass gzip -d "$DATABASE.sql.gz" psql -h $SERVER -U $USER -d $DATABASE -t -c "SELECT 'DROP TABLE ' || n.nspname || '.' || c.relname || ' CASCADE;' FROM pg_catalog.pg_class AS c LEFT JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind = 'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid)" > droptables psql -h $SERVER -d $DATABASE -U $USER -f droptables psql -h $SERVER -U $USER $DATABASE -f $DATABASE.sql rm "$DATABASE.sql" hg revert "$DATABASE.sql.gz"
https://www.fermasoft.com/HowTo/DropPostgreSQLTables
Reply
Anonymous
1. su - postgres 2. psql 3. ALTER ROLE dcms WITH SUPERUSER CREATEDB CREATEROLE REPLICATION; 3. check: \du should be like: Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- dcms | Superuser, Create role, Create DB, Replication | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
05.06.17
Reply
Anonymous
Information Epoch 1732511790
Use lower case and keep it short.
Home
Notebook
Contact us