Linux command
postgres 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Start PostgreSQL server
postgres -D [/var/lib/postgresql/data]
Start in foreground with logging
postgres -D [/var/lib/postgresql/data] -c log_statement=all
Start on specific port
postgres -D [/var/lib/postgresql/data] -p [5433]
Start single-user mode
postgres --single -D [/var/lib/postgresql/data] [database]
Show version
postgres --version
说明
postgres is the PostgreSQL database server process. It manages database files, handles connections, and executes SQL queries. The server is typically started through pg_ctl or system service managers rather than directly. Direct invocation is useful for debugging or non-standard configurations. Configuration parameters can be set on command line or in postgresql.conf. Runtime parameters control memory, connections, logging, and behavior. Single-user mode bypasses normal startup for maintenance. It's used for recovery operations when the database won't start normally. The data directory contains all database files. It must be initialized with initdb before first use and is not portable between major versions. Logging options help diagnose problems. Statement logging shows all SQL. Connection logging tracks client access.
参数
- -D _DIR_
- Data directory.
- -p _PORT_
- Port number.
- -c _NAME=VALUE_
- Set runtime parameter.
- -h _HOST_
- Listen addresses.
- -k _DIR_
- Unix socket directory.
- -l _FILE_
- Send server log output to a file.
- -d _LEVEL_
- Set debug level (1-5); higher values produce more output.
- -B _BUFFERS_
- Shared buffers.
- -N _N_
- Max connections.
- --single
- Single-user mode. Must be the first argument on the command line.
- -e
- Echo all commands to standard output (single-user mode).
- -F
- Disable fsync for faster operation (risk of data corruption).
- --describe-config
- Describe configuration parameters and exit.
- --version
- Show version.
FAQ
What is the postgres command used for?
postgres is the PostgreSQL database server process. It manages database files, handles connections, and executes SQL queries. The server is typically started through pg_ctl or system service managers rather than directly. Direct invocation is useful for debugging or non-standard configurations. Configuration parameters can be set on command line or in postgresql.conf. Runtime parameters control memory, connections, logging, and behavior. Single-user mode bypasses normal startup for maintenance. It's used for recovery operations when the database won't start normally. The data directory contains all database files. It must be initialized with initdb before first use and is not portable between major versions. Logging options help diagnose problems. Statement logging shows all SQL. Connection logging tracks client access.
How do I run a basic postgres example?
Run `postgres -D [/var/lib/postgresql/data]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -D _DIR_ do in postgres?
Data directory.