Postgres error message (in pgAdmin): "database 'postgres' does not exist", after 'postgres' table droped - postgresql

In order to organize my local database server, I've executed DROP DATABASE postgres;. After it when I try to connect to database, it shows an error message:
database "postgres" does not exist
I've restarted the service; I've tried to reinstall postgres (install file:'postgresql-12.11-1-windows-x64'); I've tried to change the 'method' of file 'pg_hba.conf', from 'md5' to 'trust'. But the error continues.
Please, how can I create this 'postgres' database? Or other solution?

I've created a new server and then a new database. When I was recreating a database, I identified that the database 'postgres' is automacally created, and to create a my database is necessary set a owner, and by default the owner is 'postgres'.
Note: Maybe this suggestion (How to recover or recreate orginal Postgres database after dropping it?) could be work, when I saw this reply I'd already soluted how I described above.

Related

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:

FATAL: password authentication failed for user "postgres" While connecting to postgres

I tried to create server it it says:
Unable to connect to server:
FATAL: password authentication failed for user "postgres"
https://prnt.sc/ric1vl
What operating system are you using? maybe you need to change the password of the postgres user. In my case I use Debian GNU Linux, to change the password of the postgres user, I do it in the following way:
root#alpha:~$ passwd postgres
and then I enter a new password for the user.
Could you also verify that the postgres user has permission to connect to the server? To do this, you can check the pg_hba.config file in the PostgreSQL. installation directory.
root#alpha:~$ nano /etc/postgresql/11/main/pg_hba.conf
By default PostgreSQL, only allows connections from local addresses (localhost)
Make sure to have your local postgres server running
Hit pgadmin tool connect to server and to create database
Right-click on the server button to your left, select create then server, insert name of the server, make sure it is as descriptive as possible, that way you can find your way back to if you remember
Move to connection tab; host name is the server where the SQL database is running, most likely you will be starting with your machine as database(db), insert localhost or 127.0.0.1.
leave default port as it is '5432'
maintenance db leave as 'postgres'
username leave as default 'postgres'
password : same as you registered with during installation
To your left, you should see the database under 'server', you should see the postgres default created underlink databases.
Right click on the databases button and select create, then database, insert your descriptive database name, click save.
Click on your new database, roll down, highlight Schema, go to Tools, select Query Tool...
You can go ahead to create or import tables as you deem fit.
EMPHASIS SHOULD BE ON THE PASSWORD, IT MUST BE SAME AS USED DURING INSTALLATION

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.

Postgresql Ubuntu strange behaviour (version incompatibility?)

I'm trying to run a postgresql Database on Ubuntu 16.04 LTS.
First I installed postgres using sudo apt-get install postgresql which installed version 9.5.1. I then created another user and a new database. I've granted all privileges for the new database to new new user and set the owner to the new user also.
I connected to the new database and filled it by restoring an plain backup (dump) I've created from another database (which has postgresql version 9.2) by using \i /path/to/dump.sql. I got no errors, and when I then typen \dt I got the list with the tables.
The problem is: When I now disconnect (\q) and re-connect (same as I connected before, sudo psql -U "username" dbname) and type \dt again, it says "No relations found". When I try to fill it again, I get a bunch of errors like "Relation relationname already exists".
Another problem/symptom appears when I try to use pgAdmin (installed via sudo apt-get install pgadmin3). When trying to connect using localhost, I can't connect using the newly created user (which which I can connect from the terminal). But I can connect using postgres with the password I set via Terminal. I do not see any DB I manually create from command line from pgAdmin tho.
So yeah, my guess is that at least one problem may be version incompatibility between 9.2 and 9.5. Is there any way to test/fix this? But I also think there should be other problems.
What you describe may happen if the SQL dump contains a SET search_path TO...command that sets it to a different value than what your user has by default.
So not only it will create its tables and other objects in that schema, but it will leave that search_path for the rest of the session, so when you do \dt in that same session, it does see and list the newly created tables.
But when you quit and reenter psql, this search_path is not longer in effect, you're back to the default search_path of your user, which supposedly doesn't reach the schema, so \dt no longer "sees" any table.
You can use show search_path to check this setting in a psql session, and grep "SET search_path" in the SQL file to check what it's being set to.
Per comment, it appears to be the case: the dump creates the tables into a schema that is outside of the user's default search path.
A possible solution for that user to work seamlessly would be to update its search path so that it always reaches this schema first. This can be done with:
ALTER USER username SET search_path TO schema1,"$user",public;
where schema1 is what the SQL dump refers to and where it created the tables.

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