Home
Available on AWS Marketplace

PostgreSQL 17 + pgAdmin4

Amazon Linux 2023 | Production-Ready | Auto-Tuning

Complete AMI guide for your PostgreSQL 17 + pgAdmin4. Learn how to access your database, find credentials, and configure your instance for production use.

PostgreSQL 17.7 pgAdmin4 9.11 Amazon Linux 2023

Quick Start Guide

Follow these steps to access your PostgreSQL database and pgAdmin4 web interface.

1

SSH to Your Instance

Connect to your EC2 instance using SSH with your key pair.

ssh -i your-key.pem ec2-user@<your-instance-ip>
2

Find Your Credentials

View the auto-generated PostgreSQL and pgAdmin4 passwords.

sudo cat /var/lib/pgsql/credentials.txt
3

Access pgAdmin4

Open pgAdmin4 in your browser using your instance's public IP.

http://<your-instance-ip>/pgadmin4

Login with:
Email: admin@localhost
Password: (from credentials file)

4

Connect to PostgreSQL

Connect via command line or add a server in pgAdmin4.

# On the instance: sudo -u postgres psql # From remote: psql -h <your-instance-ip> -U postgres -d postgres

Credentials & Connection Details

All credentials are automatically generated and stored securely on your instance.

PostgreSQL

  • Username: postgres
  • Port: 5432
  • Password: See credentials file
  • SSL: Enabled (TLSv1.3)

pgAdmin4

  • URL: http://<your-ip>/pgadmin4
  • Email: admin@localhost
  • Password: See credentials file

Credentials File Location

sudo cat /var/lib/pgsql/credentials.txt

Connection String Format

postgresql://postgres:<password>@<your-instance-ip>:5432/postgres?sslmode=require

Using pgAdmin4

pgAdmin4 is a powerful web-based administration tool for PostgreSQL. Here's how to get started.

1

Login to pgAdmin4

Open your browser and navigate to the pgAdmin4 URL.

http://<your-instance-ip>/pgadmin4

Email: admin@localhost
Password: (from credentials file)

2

Add Server Connection

Register your PostgreSQL server in pgAdmin4.

  • 1. Right-click ServersRegisterServer...
  • 2. General tab: Name = "PostgreSQL 17"
  • 3. Connection tab:
  • • Host: localhost
  • • Port: 5432
  • • Username: postgres
  • • Password: (from credentials file)
  • 4. Click Save
3

Create a Database

Create a new database for your application.

  • 1. Expand your server in the left panel
  • 2. Right-click Databases
  • 3. Select CreateDatabase...
  • 4. Enter your database name
  • 5. Click Save
4

Run SQL Queries

Use the Query Tool to execute SQL commands.

  • 1. Select your database in the left panel
  • 2. Click ToolsQuery Tool
  • 3. Type your SQL query in the editor
  • 4. Press F5 or click Execute (▶)
  • 5. View results in the Data Output panel

Common pgAdmin4 Tasks

Backup Database

Right-click database → Backup...
Choose format (custom, tar, plain) and destination.

Restore Database

Right-click database → Restore...
Select your backup file and restore options.

View Table Data

Right-click table → View/Edit DataAll Rows
Browse, filter, and edit data directly.

Monitor Activity

Click Dashboard tab on server.
View active sessions, locks, and live statistics.

Create Tables

Right-click TablesCreateTable...
Define columns, constraints, and indexes.

Import/Export Data

Right-click table → Import/Export Data...
Supports CSV, binary, and text formats.

pgAdmin4 Tips

  • Use localhost (not your instance IP) when connecting from pgAdmin4 since it runs on the same server.
  • The Master Password protects your saved server passwords. Set it on first use.
  • Access Query History in the Query Tool to re-run previous queries.
  • Change your pgAdmin4 password via User menu (top right) → Change Password.

Security Recommendations

Follow these steps to secure your PostgreSQL deployment.

Important: Change the default passwords immediately after your first login. The pre-generated passwords should only be used for initial access.

Change Passwords

Update PostgreSQL password via psql and pgAdmin4 password via the web interface.

Security Groups

Restrict port 5432 access to only your IP addresses or VPC CIDR range.

SSL/TLS Enabled

SSL is enabled by default. All connections use TLSv1.3 encryption.

Change PostgreSQL Password

sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'your-new-secure-password';"

Troubleshooting

Common issues and how to resolve them.

Can't Connect Remotely

Symptom: Connection refused or timeout when connecting from your machine.

Solution:

  • 1. Check your EC2 Security Group allows inbound on port 5432
  • 2. Verify your IP is whitelisted in the security group
  • 3. Ensure PostgreSQL is running: sudo systemctl status postgresql

pgAdmin4 Login Fails

Symptom: Can't log in to pgAdmin4 web interface.

Solution:

  • 1. Verify credentials: sudo cat /var/lib/pgsql/credentials.txt
  • 2. If account locked, unlock it:
  • sudo sqlite3 /var/lib/pgadmin4/pgadmin4.db "UPDATE user SET locked=0, login_attempts=0 WHERE id=1;"
  • 3. Restart pgAdmin4: sudo systemctl restart pgadmin4

Connection Timeout

Symptom: Connections hang and eventually time out.

Solution:

  • 1. Verify instance is running in EC2 console
  • 2. Check you're using the correct public IP
  • 3. Ensure port 80 (pgAdmin4) or 5432 (PostgreSQL) is open
  • 4. Check if instance has a public IP assigned

Password Authentication Failed

Symptom: "password authentication failed for user postgres"

Solution:

  • 1. Check the password from credentials file
  • 2. Reset password if needed:
  • sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'newpassword';"
  • 3. Use alphanumeric passwords only (avoid special chars)

Frequently Asked Questions

Common questions and quick solutions.

How do I reset my PostgreSQL password?

sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'newpassword';"

How do I check PostgreSQL logs?

sudo tail -100 /pgdata/postgresql/logs/postgresql-$(date +%Y-%m-%d).log

How do I restart PostgreSQL?

sudo systemctl restart postgresql

How do I restart pgAdmin4?

sudo systemctl restart pgadmin4 httpd

Where is PostgreSQL data stored?

Data is stored on a separate EBS volume:

/pgdata/postgresql/data

How do I check service status?

sudo systemctl status postgresql pgadmin4 httpd

Instance Sizing Guide

Choose the right EC2 instance type for your workload.

Use Case Instance Type vCPUs RAM Recommended For
Development t3.small 2 2 GB Testing, learning, small dev projects
Small Production t3.medium 2 4 GB Small apps, low traffic websites
Medium Production m6i.large 2 8 GB Medium traffic, business applications
Large Production m6i.xlarge 4 16 GB High traffic, enterprise workloads
High Performance r6i.xlarge 4 32 GB Memory-intensive, analytics, large datasets

Auto-Tuning Note

  • PostgreSQL automatically tunes itself on first boot based on your instance's RAM and CPU.
  • You can resize your instance at any time - PostgreSQL will re-tune on next reboot.
  • For production, use m6i or r6i instances for consistent performance (not burstable).

Backup & Recovery

Protect your data with regular backups.

EBS Snapshots (Recommended)

The easiest way to back up your entire database.

  • Go to EC2 Console → Volumes
  • Select the data volume (20GB, mounted at /pgdata)
  • Actions → Create Snapshot
  • Enable automated snapshots via AWS Backup

pg_dump (Logical Backup)

Export databases to SQL files.

# Backup single database sudo -u postgres pg_dump mydb > mydb_backup.sql # Backup all databases sudo -u postgres pg_dumpall > all_databases.sql # Custom format (compressed) sudo -u postgres pg_dump -Fc mydb > mydb.dump

Restore from Backup

Restore databases from SQL or dump files.

# Restore from SQL sudo -u postgres psql mydb < mydb_backup.sql # Restore from custom format sudo -u postgres pg_restore -d mydb mydb.dump # Create db and restore sudo -u postgres createdb newdb sudo -u postgres pg_restore -d newdb mydb.dump

Backup Schedule

Recommended backup frequency:

  • Daily: EBS snapshots (automated)
  • Weekly: pg_dumpall for off-site storage
  • Before changes: Manual snapshot before upgrades
  • Retention: Keep 7 daily, 4 weekly snapshots

PostgreSQL Extensions

Your AMI comes with these production-ready extensions pre-installed and enabled.

Extension Description
pg_stat_statements Query performance monitoring and statistics
pgcrypto Cryptographic functions for encryption/hashing
uuid-ossp UUID generation functions
hstore Key-value pair storage within a single value
pg_trgm Trigram text similarity and search
btree_gist GiST index operator classes for common types
btree_gin GIN index operator classes for common types
citext Case-insensitive text data type
tablefunc Crosstab and pivot table functions
unaccent Text search dictionary for accent removal

Auto-Tuning

PostgreSQL is automatically configured based on your instance size.

How It Works

On first boot, the auto-tuning service detects your instance's RAM and CPU count, then calculates optimal PostgreSQL settings.

  • shared_buffers: 25% of RAM
  • effective_cache_size: 75% of RAM
  • max_parallel_workers: Based on CPU count

Configuration Files

Key configuration and log file locations:

  • Config: /pgdata/postgresql/data/postgresql.conf
  • HBA: /pgdata/postgresql/data/pg_hba.conf
  • Tuning Log: /var/log/pg-auto-tune.log
  • Data Dir: /pgdata/postgresql/data

Need Help?

Our team is available 24/7 to assist you with any questions or issues.

support@flowopsconsulting.co.uk
24/7 Support Available