温馨提示×

如何在Debian PgAdmin中创建数据库

小樊
37
2025-11-10 23:08:19
栏目: 智能运维

Prerequisites
Before creating a database in pgAdmin on Debian, ensure:

  • PostgreSQL server is installed and running (sudo apt install postgresql postgresql-contrib && sudo systemctl start postgresql && sudo systemctl enable postgresql).
  • pgAdmin4 is installed (sudo apt install pgadmin4).
  • A pgAdmin server connection is configured (follow steps in the “Configuring pgAdmin” section below).

Steps to Create a Database in pgAdmin

1. Configure pgAdmin Server Connection

To manage PostgreSQL databases via pgAdmin, you must first add a server connection:

  • Open pgAdmin in your browser (e.g., http://localhost:5050) and log in.
  • In the left navigation pane, right-click the Servers node and select Create > Server.
  • In the General tab, enter a descriptive name (e.g., “Local PostgreSQL”).
  • Switch to the Connection tab and fill in:
    • Host: localhost (for local connections) or the server’s IP address.
    • Port: 5432 (default PostgreSQL port; change if modified in postgresql.conf).
    • Maintenance database: postgres (default system database).
    • Username: The PostgreSQL superuser (e.g., postgres) or a custom user with permissions.
    • Password: The password for the selected user.
  • Click Save to establish the connection. The server will appear under the Servers node.

2. Create a Database

Once connected to the server, follow these steps to create a database:

  • In the left navigation pane, expand the connected server node.
  • Right-click the Databases node and select Create > Database.
  • In the Create - Database dialog, configure the following:
    • General tab:
      • Database name: Enter a unique name (e.g., myapp_db).
      • Owner: Select a user (e.g., pgadmin_user; created in the “Prerequisites” section) who will own the database.
    • Optional Settings (adjust as needed):
      • Character encoding: Use UTF8 (recommended for compatibility).
      • Collation/Locale: Keep default unless specific localization is required.
      • Connection limits: Set maximum connections (e.g., -1 for unlimited).
  • Click Save to create the database. The new database will appear under the Databases node.

Key Notes

  • If you encounter connection issues, verify:
    • PostgreSQL service is running (sudo systemctl status postgresql).
    • postgresql.conf allows connections (listen_addresses = '*') and pg_hba.conf grants access to your IP.
    • Firewall allows port 5432 (for local access, ufw allow 5432/tcp).
  • For remote servers, replace localhost with the server’s IP and ensure PostgreSQL is configured to accept remote connections.

0