OpenShift PostgreSQL Database Restore - postgresql

I have an OpenShift App that uses the PostgreSQL database.
I want to restore this database with data from a 'live' database.
When running locally, I just drop the database. Then I create the database and then run the restore.
But, when I try and drop the database on OpenShift, it says:
dropdb: database removal failed: ERROR: database "test" is being accessed by other users
So I stopped the OpenShift App and then retried
Now it says:
pg_restore: [archiver (db)] connection to database "test" failed: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/lib/openshift/123456ef0c1e123456789b/postgresql/socket//.s.PGSQL.5432"?
So I have a catch 22 situation.
What is the correct way to restore a PostgreSQL database on OpenShift?

Leave Postgresql running but stop the application that was accessing the database. It's that simple...

Related

UnhandledPromiseRejectionWarning: SequelizeConnectionError: database "dbname" does not exist

While trying to connect to a DB instance running the PostgreSQL database engine on Amazon RDS.
I have checked the environment variables and the values are set correctly.
However, when I run npm run dev I encounter the error below
(node:32031) UnhandledPromiseRejectionWarning: SequelizeConnectionError: database "database-1" does not exist
My DB is publicly accessible and security groups have been checked to be correct(allows inbound and outbound connection).
Was able to solve this by using the default database name postgres for the env --dbname option.

Amazon RDS postgres Data wiped and can't connect to database?

I created an RDS Postgres instance. I'm new to RDS.
db host:
demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com
db identifier:
demodb
Every tutorial says to connect with this URL:
jdbc:postgresql://demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com:5432/demodb
but every time I do I get this error-
FATAl: database "demodb" does not exist.
I am able to connect using this:
jdbc:postgresql://demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com:5432/postgres
Now, while I was excited to connect after I used SQL workbench to create tables and insert data into those tables, a few hours later all my tables and data were deleted/wiped/dropped. Why would this happen? and How can I prevent it from happening in the future?
FATAl: database "demodb" does not exist.
demodb is db instance identifier. It is NOT the name of your database inside of PostgreSQL.
By default RDS PostgreSQL does not create a database for you. It seems to me that you haven't created an actual database when you setup your RDS PostgreSQL.
To create a database at RDS creation there is an option called Initial database name where you should specify the name of the database you want. Otherwise, no database is created, which is a default behavior:

Cannot drop db in postgres [duplicate]

I can't seem to reset my database while using docker compose. I've tried killing the server, killing just the database, and restarting the machine.
Anyone know the best way to clear out the development database?
Here's what I tried:
docker-compose run web rake db:reset
I am getting this error:
PG::ObjectInUse: ERROR: cannot drop the currently open database
: DROP DATABASE IF EXISTS "postgres"
Couldn't drop database 'postgres'
rake aborted!
I'm using the setup exactly as described by the docker-compose quickstart: https://docs.docker.com/compose/rails/
I have a rails container and a postgres container
You are using the wrong database.
The database postgres is normally not used for user data, but for administrative purposes. For example, if you want to drop a database, you have to be connected to a different database in the PostgreSQL database cluster to issue the SQL statement DROP DATABASE. Normally, the database postgres is used for that purpose, and I have no doubt that Docker does exactly that when it tries to drop a database.
If you really want to drop the database postgres, you'd have to connect to some other database in the cluster. The correct solution, however, is to keep your data in a different database. Then the problem should go away by itself.

How to get the PostgreSQL db backup from slave if master down

I have setup PostgreSQL hot stand by replication on Ubuntu. I need to know if master DB server is down, then how to get the backup from the slave.
I have tried this command
pg_dump testdb > /var/lib/postgresql/20190306.bak -p 5433
I got this error:
pg_dump: [archiver (db)] connection to database "channeldb" failed:
FATAL: role "root" does not exist
This specific error has nothing to do with this being a standby server.
Rather, you forgot to use the -U option to specify the database user, so pg_dump assumes it is the same as the operating system user.
Don't use the root user for anything but administrative activities!

postgresql data directory not connecting

I am using windows 8.
My Postgres was Correct.
I just took the data directory from C:/postgresql/8.3/
Now database was connected through command prompt.
When I was trying to connect using pgadmin, it's saying
FATEL: error
An error has occured:
Error connecting to sthe server: FATAL: role "postgres" is not permitted to log in
I changed the required things in pg_hba.conf (trust) and postgresql.conf (connection *) (port 5433)
But, still I was unable to connect the database.
How to give the permissions to postgres role.
when am trying to give the permissions through cmd also it's giving same error.
I was tried in so many ways
but, still I didn't get the database.
It looks like you might have accidentally revoked the LOGIN and SUPERUSER rights from the postgres user. Perhaps you created a superuser with a different name instead? Log in as that user if you did.
If not, and you can't get access as user postgres, you will need to start the database engine up in single-user mode and manually GRANT the SUPERUSER right to postgres again. This is much the same process as is required when recovering from a dropped (deleted) superuser account.
See related:
https://dba.stackexchange.com/q/44586/7788
Postgres reset password in PostgreSQL server 8.4
BTW, 8.3 is a very old and unsupported version. Plan your upgrade promptly.
If there's no data in PostgreSQL that you care about, the easiest thing to do will be:
Uninstall PostgreSQL 8.3;
Delete C:\Program Files\PostgreSQL\8.3 (permanently and unrecoverably destroying all data in your PostgreSQL databases); and
Install a current PostgreSQL version