
Pgadmin 4 in PostgreSql
pgAdmin 4 in PostgreSQL β A Beginnerβs Guide π
pgAdmin 4 is a GUI tool for managing PostgreSQL databases. It allows you to create, modify, and query databases visually.
1. Install pgAdmin 4
Windows (Recommended)
- Download the installer from pgAdmin official website.
- Run the installer and follow the setup instructions.
- After installation, launch pgAdmin 4 from the Start menu.
Ubuntu/Debian (Linux)
sudo apt updatesudo apt install pgadmin4
macOS (Using Homebrew)
brew install --cask pgadmin4
Docker (Alternative)
docker run -p 5050:80 -e PGADMIN_DEFAULT_EMAIL=admin@example.com -e PGADMIN_DEFAULT_PASSWORD=admin -d dpage/pgadmin4
Access pgAdmin 4 in your browser at http://localhost:5050
.
2. Open pgAdmin 4 & Connect to PostgreSQL
- Launch pgAdmin 4
- Click on "Add New Server"
- Enter the connection details:
- Name: PostgreSQL (or any name)
- Host:
localhost
(or your remote server IP) - Port:
5432
(default) - Username:
postgres
- Password: (Enter your PostgreSQL password)
- Click Save, and your database should appear in the left panel.
3. Create a Database Using pgAdmin
- Right-click on Databases β Create β Database
- Enter a name (e.g.,
mydb
) - Click Save
4. Create a Table Using pgAdmin
- Expand Databases β mydb β Schemas β public
- Right-click Tables β Create β Table
- Enter a table name (
users
) - Click on Columns β Add Column:
- Name:
id
, Type:SERIAL
, Primary Key - Name:
name
, Type:VARCHAR(100)
- Name:
email
, Type:VARCHAR(150)
(Unique)
- Name:
- Click Save
5. Insert Data Using pgAdmin
- Right-click on users β Query Tool
- Run the SQL query:
INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com'), ('Bob', 'bob@example.com');
- Click Execute (βΆοΈ button)
6. Query Data in pgAdmin
- Open Query Tool
- Run the query:
SELECT * FROM users;
- Click Execute (βΆοΈ button)
7. Backup & Restore Databases in pgAdmin
Backup
- Right-click on the database mydb β Backup
- Choose a location and format (
.backup
) - Click Start
Restore
- Right-click on Databases β Create β Database (if not exists)
- Right-click on the database β Restore
- Select the
.backup
file and click Restore
8. Manage Remote PostgreSQL Servers in pgAdmin
If you want to connect to a remote PostgreSQL server, follow these steps:
On the Remote Server
- Edit postgresql.conf
Change:sudo nano /etc/postgresql/15/main/postgresql.conf
listen_addresses = '*'
- Edit pg_hba.conf
Add:sudo nano /etc/postgresql/15/main/pg_hba.conf
host all all 0.0.0.0/0 md5
- Restart PostgreSQL:
sudo systemctl restart postgresql
On pgAdmin 4
- Add New Server
- Use the remote IP address instead of
localhost
- Save and connect
9. Common Errors & Fixes
Error | Solution |
---|---|
could not connect to server | Check if PostgreSQL service is running (sudo systemctl status postgresql ) |
FATAL: password authentication failed | Ensure you are using the correct username & password |
connection refused (0x0000274D/10061) | Check listen_addresses in postgresql.conf |
10. Next Steps
β
Integrate PostgreSQL with Go Fiber
β
Learn advanced SQL (Joins, Views, Indexing, Transactions)
β
Automate database tasks using pgAgent