Error in Postgres TX - postgresql

Trying to create a user in the database and it's telling me that cannot execute **** in a read-only transaction. I have no idea what's causing this? Is this a bad state in the database or connection? Why is this telling that it's not in a transaction but then telling me it's a read-only transaction? Does "transaction" refer to the same thing?
$ psql --host localhost --port 5432 --username **** postgres --no-password -v dbuser=root -t -X
psql (10.1, server 9.4.13)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
postgres=# set transaction read write;
WARNING: SET TRANSACTION can only be used in transaction blocks
ERROR: cannot set transaction read-write mode during recovery
postgres=# CREATE USER root WITH PASSWORD 'root';
ERROR: cannot execute CREATE ROLE in a read-only transaction

Your database is in recovery.
Either it is a hot standby (most likely), or recovery was paused with SELECT pg_wal_replay_pause() or recovery_target_action = 'pause' in recovery.conf (check with SELECT pg_is_wal_replay_paused()), or a point-in-time-recovery is still running.
Use the primary or complete recovery.

Related

How can connect psql with normal user without specifying database name?

I can connect mysql with username without specifying any database name,showkey is one of mysql user:
mysql -u showkey -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.3.31-MariaDB-0+deb10u1 Debian 10
Now i log into mysql without specifying any database name.showkey is also a normal user for my postgresql,test is a database name in my postgresql.
psql -d test -U showkey
Timing is on.
Pager usage is off.
Null display is "missing data".
psql (11.14 (Debian 11.14-0+deb10u1))
Type "help" for help.
test=#
I conncet the test database with a normal user showkey,now want to connect postgresql with normal user without specifying database name such way as in mysql:
psql -U showkey
psql: FATAL: database "showkey" does not exist
sudo -u postgres psql can connect postgresql with a super user instead of with normal user.

How to connect remote postgresql database from kong application?

I have a kong services which is in failed status with below error message from journalctl
/usr/local/share/lua/5.1/kong/cmd/migrations.lua:213: [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: FATAL: password authentication failed for user "konguser"
postgres information from Kong.conf as below
cat /etc/kong/kong.conf|grep -i pg
pg_host = xxxx.yyyyy.ap-south-1.rds.amazonaws.com
pg_port = 5432 # Port of the Postgres server.
pg_user = konguser # Postgres user.
pg_password = "zzzzzzz" # Postgres user's password.
pg_database = kong_db # The database name to connect to.
Troubleshooted the same by trying to connect the same manually using psql as below and it worked
[root#ip-10-0-2-30 system]# psql -U konguser -p 5432 -h xxxx.yyyyy.ap-south-1.rds.amazonaws.com -d kong_db
Password for user konguser:
psql (10.15, server 10.9)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
kong_db=>
Not sure what is causing the failure.Could you please help to troubleshoot
Looks like your rds instance is using ssl.
Default kong configuration is without ssl.
https://docs.konghq.com/gateway-oss/2.4.x/configuration/#postgres-settings
Two solution, remove ssl from rds, or activate it on kong side with
pg_ssl=on

AWS EC2 Postgres authentication failed

I did setup Postgres-12 on Centos AMI EC2, It works well.
However, Sometimes (my case is the next day) I can not connect my DB by trying
$psql -h XXXX -p5432 -Upostgres
A authentication failed error
psql: error: could not connect to server: FATAL: password authentication failed for user "postgres"
Next, I change my postgres user again by
$sudo su - postgres
~]$ psql -c "alter user postgres with password 'postgres'"
The connection login become work.
But sometimes it become not work again (same above authentication failed)
I reset postgres password the same above command => The connection login become work.
It repeats #2
I don't know why. Does anybody know that? What should I do?
I realize that the my Postgres use very much CPU (%CPU: 99%).
hat could be solution to this problem. I would appreciate any suggestions.
Thank you

pg_dump connection to database "db_name" failed: FATAL: Peer authentication failed for user "postgres"

I am trying to take the pg_dump of a database from my local system by running the following command in my terminal:
mypc#mypc:~$ pg_dump -U postgres existing_db_name > dbexport.sql
And I am getting this following error.
pg_dump: [archiver (db)] connection to database "db_name" failed: FATAL: Peer authentication failed for user "postgres"
It is not even prompting for password.
You can pass the password as an environment variable PGPASSWORD. You can fire this off as a single command eg.
PGPASSWORD="password" pg_dump -U postgres existing_db_name > dbexport.sql
Or you can adjust your hba.conf file and set the user postgres to trust on local connections. From the error its likely set to peer.
https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
Or you can create a .pass file
https://www.postgresql.org/docs/current/static/libpq-pgpass.html

PostgreSQL 9.5 Using ident in pg_hba

I am working on a local network based on Windows, and I would like to use the account system of the network to allow users to connect to my DB.
As I understand the proper way is to set the pg_hba method on "ident" as such :
host all all 10.0.0.0/8 ident
But when I do so I get a message saying
"Error connecting to the server: FATAL: ident authentication failed for user <user>"
As far as I can think of it, my guess is that there could be two problems :
- I do not properly set the pg_hba.
- The role I created does not match the ident found by the server.
In the first case, could you tell if the syntax is correct ? I tried to add "sameuser" after the ident, but it corrupt my pg_hba, and also map=sameuser, but I get the same error as mentionned.
In the second case, I am using a batch run on every session to get the users names like
find /c "%username%"
or the Python3.6 function os.getlogin(), which produce the same result.
How does PostgreSQL get its "ident" ? And more importantly, how can I reproduce this process to know the idents of the sessions that PostgreSQL will recognize ?
Thanks.
after reading ident.conf manual and using the example from hba_file manual, I set this up:
postgres=# create user ident_user_db;
CREATE ROLE
vao#vao-X102BA:~$ sudo tail -n 1 /etc/postgresql/9.6/main/pg_hba.conf
host all all 192.168.8.0/24 ident map=vao_ident
vao#vao-X102BA:~$ sudo tail -n 1 /etc/postgresql/9.6/main/pg_ident.conf
vao_ident vao ident_user_db
Now I'm connecting from same machine to its external IP:
vao#vao-X102BA:~$ psql -h 192.168.8.107 -U ident_user_db
psql: FATAL: Ident authentication failed for user "ident_user_db"
FATAL: Ident authentication failed for user "ident_user_db"
Seems familiar. Though I followed manual. Last thing to check:
vao#vao-X102BA:~$ telnet localhost 113
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
So nothing provides my identity. As advised here
vao#vao-X102BA:~$ sudo apt-get install oidentd
...
vao#vao-X102BA:~$ telnet localhost 113
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
so try now:
vao#vao-X102BA:~$ psql -h 192.168.8.107 -U ident_user_db -d vao
psql (9.6.3)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
Hope it helps