psql: database "template0" is not currently accepting connections - greenplum

We have Installed fresh gpdb database.But,when trying to connect with template0 database.
[gpadmin#mdw~]$ psql -d template0
psql: FATAL: database "template0" is not currently accepting connections
[gpadmin#mdw~]$
We tried to Update the FLAG
template1=# UPDATE pg_database SET datallowconn = TRUE WHERE datname = 'template0';
ERROR: permission denied: "pg_database" is a system catalog
template1=#
But,it is not allowing to Update The FLAG

There is no reason to connect to template0. Even template1 should not be used, because that is the default template for newly created databases. If you create something in template1, it will be copied into any new database. That is easy to forget if you use template1 to connect to the database and then forget to switch databases.
You can use the postgres database for connections. That one is not used otherwise.

Related

Postgresql setup

I'm learning Ruby and Postgresql and I'm trying to run a db project where I'm running this file to get started:
#!/usr/bin/env sh
dropdb sqlzoo
createdb sqlzoo
psql sqlzoo < data/create_tables.sql
But I get this output in the console:
dropdb: could not connect to database template1: FATAL: role "my_name" does not exist
createdb: could not connect to database template1: FATAL: role "my_name" does not exist
psql: FATAL: role "my_name" does not exist
When logging into PSQL it shows that user <my_name> is a Superuser. The template1 db is there by default.
How can I proceed here to get this setup working?

FATAL: no pg_hba.conf entry for host when setting up blazer gem

My application uses the blazer gem for visualizing DB queries.
During the setup I've encountered the following error:
FATAL: no pg_hba.conf entry for host "111.22.33.44", user "blazer", database "my_db", SSL off
My application is hosted on EngineYard and uses PostgreSQL.
How can I find and modify the pg_hba.conf on EngineYard?
upd
I do have SSH access to EngineYard cloud.
Instance: General Purpose (M3) Large.
OS: EngineYard's Gentoo.
You can try the following steps. I've assumed that your DB name is my_db.
Connect to the instance via SSH (the link can be found on the EngineYard environment page)
Connect to the
database as superuser psql -U postgres -h localhost -d
my_db. If you don't have the password, check your database secrets here /data/my_db/current/config/database.yml
After connecting to DB identify location of hba file by typing SHOW
hba_file;
Quit psql by typing \q
Use previously identified path to open the hba_file file and add the missing user. E.g via vim sudo vim /db/postgresql/9.5/data/pg_hba.conf. Note the sudo command
The use should be added under # IPv4 postgres
user for 10.x with md5:
Connect to the database again
Reload the configuration via select pg_reload_conf(); command
After all steps are performed, Blazer queries should be accessible.

Windows: how can I set my PostgreSQL user to the superuser?

I am trying to create a database using PostgreSQL 9.4. I type "psql" in the command prompt, and then it asks for a password. I provide the password I set during the installation, but it says the authentication failed. After checking online, I concluded that I need to be using the superuser, named "postgres", which is the system user whose password is the one I set during the installation.
I am now trying to set PostgreSQL to this superuser. I spent a lot of time surfing the internet for a solution but wasn't able to solve the problem. I tried postgres ALTER USER myuser WITH SUPERUSER (I wrote that in the Windows command prompt), but it said that "alter" isn't recognized. Now, when I try to use PostgreSQL, my main problem is that I get the error: "role MYUSERNAME does not exist". (this is after I edited pg_hba.conf to make it not ask for a password)
By default, psql uses the name of the operating system to log in, to a database of the same name. If you want to log in as user postgres you should do:
psql -u postgres <any other options>
If a password is asked for, you give the password of the postgres user. You are now connected to the postgres database, where you really shouldn't be doing anything, except create new users (which are global to the installation) and other databases.
Once in the console, you can create new users like:
CREATE ROLE myusername LOGIN PASSWORD secret;
And new databases like:
CREATE DATABASE myowndb;
ALTER DATABASE myowndb OWNER TO myusername;
Then you log out from the console with \q.
In order to be able to access PostgreSQL using the new database, you have to edit the pg_hba.conf file (sample, modify to match your network settings):
host myowndb myusername 192.168.0.0/16 md5
Now you restart the PostgreSQL server from the Services tab in Administrative tools on the Control Panel.
Then you can log in to your new database:
psql -u myusername -d myowndb
Or use other clients like pgAdminIII.
Under Windows. The Postgres bin directory ships with the user commands createuser.exe and dropuser.exe.
Say, if running initdb (effective fresh install) or for some other reason there is no superuser (like the question).
Can also manage the users and superusers (-s option) with the above two commands. ie.
Create the superuser called postgres:
C:"Program Files"\PostgreSQL\15\bin\createuser.exe -s postgres
Drop a user:
C:"Program Files"\PostgreSQL\15\bin\dropuser.exe postgres

Could not connect to database postgres: FATAL: role"_postgres" does not exist

Working on OS X 10.10, installed postgreSQL and PostGIS from
here, psql vers 9.3.5. I am having a hard time getting postgreSQL running.
I installed the packages as admin on my computer. My username is christoph
The only way I can log in is via:
$ psql -U postgres
I want to create user called christoph, as my admin name on the computer.
I tried (from the terminal, without being "logged in into psql"):
$ sudo -u postgres createuser christoph
> sudo: unknown user: postgres
Then I read a little and tried (from the terminal, without being "logged in into psql"):
$ sudo -u _postgres createuser christoph
> Password: ****
> Could not connect to database postgres: FATAL: role "_postgres" does not exist
Why isn that working?
On recent version of OS X and with some installation methods the system user is created with a '_' prepended or appended to 'postgres', so the name of your system user is postgres_ or _postgres in your case, not 'postgres'. I don't use OS X, so I don't know what drives them to do this. Seems like they want to adhere to a naming schema for system accounts.
Not to be confused with the Postgres DB user (login role) of the name postgres. This mismatch causes all sorts of confusion. At least people become aware of the different meaning of some syntax elements ...
That's why you can log into Postgres via:
$ psql -U postgres
postgres is the DB role here, not the OS user.
But this won't work:
$ sudo -u postgres
Because there is no OS user of that name. Try instead:
$ sudo -u _postgres
But then peer authentication still won't work, because there is no DB user of the same name _postgres. Related answer:
Postgres user does not exist?
The authentication method activated by default in standard installations is peer authentication, where a system user on the local system has password-less access to a database role of the same name. That explains the last error message:
Could not connect to database postgres: FATAL: role "_postgres" does not exist
Your system tried to log into the DB with the same name as your current OS user using peer authentication, which fails due to the naming mismatch.
Your last command should work like this:
$ sudo -u _postgres createuser -U postgres christoph
The added -U postgres is an option to createuser specifying the DB role to log in with.
You still have to enter the password. I would consider using an entry in the a .pgpass file for password-less access, while the system user is different from the supposedly associated DB role.
Related:
Login Failed with Existing User on PostgreSQL
Run batch file with psql command without password

password authentication failed for user "postgres" on mac

I have problem creating new psql user because I cannot log in psql as "postgres", I have tried
1. sudo -u postgres psql
2. sudo -u postgres createuser img_site -P -s -e
and they are all ask for password of "postgres" which I don't know. I have tried to change unix password of user "postgres"(I know it's dangerous) and it still tells me: password authentication failed for user "postgres". I also have tried GUI pgAdmin but it's the same error.
I don't know if it's related: I have created a symbolic link
sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
in order to get rid of 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 "/var/pgsql_socket/.s.PGSQL.5432"?
Check pg_hba.conf. it should have a line like this at the top (before all other entries):
local all postgres peer
This allows local Unix-domain socket access by postgres db user to all databases with no password required.
Now clear and redefine the password for postgres system user (which is automatically created during PostgreSQL installation):
sudo passwd -d postrges
sudo su postgres -c passed
The special thing about this user account is that postgres server allows it to connect to the database, no questions asked.
Now, to define an explicit password for postgres db user using which you can login via other means than local Unix-domain socket connection, run:
su postgres -c psql template1
psql> ALTER USER postgres WITH PASSWORD '<password>';
You will be asked for the postgres system user account password before this command can be run. On successful completion, type \q to quit psql shell, and you are done with resetting the password for postgres db user.
sudo doesn't want the password of the account you're switching to, it wants the password of the account you're switching from. It also requires that you be an admin (or otherwise listead in /etc/sudoers). su, on the other hand, requires the password for the account you're switching to.
I was trying to setup postgres for Ruby on Rails and I was getting the the password authentication failed for user error. Check if the server is actually running:
pg_ctl -D /usr/local/var/postgres status
If you get
pg_ctl: no server running
Run
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Also you must include localhost in psql.
psql -U postgres -h localhost
This worked for me:
ALTER USER my_user WITH PASSWORD 'my_password';
I tried a lot of different tricks on my Macbook. And here is the one which helped me.On the screen, right click PostgreSQL14 for 'properties', then in 'connection' tab try to change port number from 5432 to 5433(or vise versa) -> save. And try to open again, for password use "postgres". Should work

Resources