I'm new to PostgreSQL.I'm using postgreSQL locally. I used it last time without any issues. Now, when I try login with my login credentials it shows the account is locked message all the time.
5 Answers
According to the pgadmin documentation there are two ways to unlock the user.
1. Updating SQLite DB (pgAdmin4.db):
Locate the pgAdmin4.db file and open it using any DB Browser (or DB Browser for SQLite)
After opening the DB file, head towards ‘Execute SQL’ section. Run below query :
UPDATE USER SET LOCKED = false, LOGIN_ATTEMPTS = 0 WHERE USERNAME = <YOUR_EMAIL_ID>
And make sure the query changes are committed.
2. Increase the MAX_LOGIN_ATTEMPTS in the pgadmin configuration file config.py or preferably add a line in config_local.py
MAX_LOGIN_ATTEMPTS = 5
-
2
-
5
As @alfredo138923 explains, you should find pgadmin4.db on your system and run a query to update the USER attempts and unlock the application for the specific user account.
But the correct SQL query must be fixed. The query parameter value must use single quotes, otherwise an error will be returned.
UPDATE USER SET LOCKED = false, LOGIN_ATTEMPTS = 0 WHERE USERNAME = '<YOUR_EMAIL>'
An example on the shell command line might be (i use Ubuntu 20.04)*:
sqlite3 pgadmin4.db "UPDATE USER SET LOCKED = false, LOGIN_ATTEMPTS = 0 WHERE USERNAME = '[email protected]';" ".exit"
*Before using sqlite3 from the command line, you need to install it as below.
apt-get install sqlite3
These solutions work very well, but if you've deployed pgadmin to a cluster or in a container, where you don't have sudo rights and the sqlite CLI tool is not installed, then you can also just use python to execute the query:
Back up your db before executing this! cp /var/lib/pgadmin/pgadmin4.db /var/lib/pgadmin/pgadmin4.db.backup
import sqlite3
db_path = '/var/lib/pgadmin/pgadmin4.db'
query = "update user set locked = false, login_attempts = 0 where username = '<admin_email>';"
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute(query)
conn.commit()
print('User should be unlocked now. Changes commited to the DB.')
Note: this script doesn't have any error checking!
Tested this with https://artifacthub.io/packages/helm/runix/pgadmin4/1.2.20 Which is using image https://hub.docker.com/r/dpage/pgadmin4/
Steps to Solve this Issue
First Locate the pgAdmin4.db in Ubuntu 20.04 you find following path
cd /var/lib/pgadmin
then run the following command
sqlite3 pgadmin4.db there might be two files but choose the file of heavy size
SQLite will be opened
now than run the command UPDATE USER SET LOCKED = false, LOGIN_ATTEMPTS = 0 WHERE USERNAME = '<YOUR_EMAIL>'
now you can login
Under Ubuntu 20.4 you must find the file vi /usr/pgadmin4/web/config.py change the MAX_LOGIN_ATTEMPTS =0 restart your server systemctl restart postgresql OR stop it then start it again systemctl stop postgresql systemctl start postgresql
-
This may explain how to prevent lock-outs in the future, but doesn't say how to unlock a user that's already locked out. And do you really need to restart Postgres when changing pgAdmin configuration? Commented Dec 30, 2021 at 15:21
psql
. This by the way is an pgAdmin issue not a Postgres one.