从 snap 安装后如何运行和配置 postgres?

从 snap 安装后如何运行和配置 postgres?

安装完成后postgres我现在该如何使用它?

postgres@mordor:~$ 
postgres@mordor:~$ whoami
postgres
postgres@mordor:~$ 
postgres@mordor:~$ pwd
/home/postgres
postgres@mordor:~$ 
postgres@mordor:~$ postegres
postegres: command not found
postgres@mordor:~$ 
postgres@mordor:~$ postegresql
postegresql: command not found
postgres@mordor:~$ 
postgres@mordor:~$ postgresql10.initialize newlocale en_US UTF-8
Generating a new locale in /home/postgres/snap/postgresql10/47/locales/en_US.UTF-8...
postgres@mordor:~$ 
postgres@mordor:~$ postgresql10.initialize initdb en_US UTF-8
Setting up PostgreSQL environment...
Data directory: /home/postgres/snap/postgresql10/common/data
Logs directory: /home/postgres/snap/postgresql10/common/logs
psql history directory: /home/postgres/snap/postgresql10/common/history
.psqlrc file: /home/postgres/snap/postgresql10/common/.psqlrc
Checking if initdb has already been run before. If not, a new cluster will be created.
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /home/postgres/snap/postgresql10/common/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... sysv
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /snap/postgresql10/47/usr/bin/pg_ctl -D /home/postgres/snap/postgresql10/common/data -l logfile start

postgres@mordor:~$ 
postgres@mordor:~$ postgresql10.pgctl -D /home/postgres/snap/postgresql10/common/data start
waiting for server to start....2020-11-14 16:20:49.231 PST [123092] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2020-11-14 16:20:49.801 PST [123092] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
.2020-11-14 16:20:50.628 PST [123093] LOG:  database system was shut down at 2020-11-14 16:20:40 PST
.2020-11-14 16:20:51.004 PST [123092] LOG:  database system is ready to accept connections
 done
server started
postgres@mordor:~$ 
postgres@mordor:~$ postgresql
postgresql: command not found
postgres@mordor:~$ postgres

Command 'postgres' not found, did you mean:

  command 'postgrey' from deb postgrey (1.36-5.1)

Try: sudo apt install <deb name>

postgres@mordor:~$ 
postgres@mordor:~$ psql

Command 'psql' not found, but can be installed with:

sudo apt install postgresql-client-common

postgres@mordor:~$ 
postgres@mordor:~$ 
postgres@mordor:~$ psql -d mydb -U myuser

Command 'psql' not found, but can be installed with:

sudo apt install postgresql-client-common

postgres@mordor:~$ 
postgres@mordor:~$ psql -h myhost -d mydb -U myuser

Command 'psql' not found, but can be installed with:

sudo apt install postgresql-client-common

postgres@mordor:~$ 
postgres@mordor:~$ psql -h localhost -d mydb -U myuser

Command 'psql' not found, but can be installed with:

sudo apt install postgresql-client-common

postgres@mordor:~$ 
postgres@mordor:~$ psql -h mordor -d mydb -U myuser

Command 'psql' not found, but can be installed with:

sudo apt install postgresql-client-common

postgres@mordor:~$ 
postgres@mordor:~$ psql --help

Command 'psql' not found, but can be installed with:

sudo apt install postgresql-client-common

postgres@mordor:~$ 

只是想在安装后创建一个数据库:

nicholas@mordor:~$ 
nicholas@mordor:~$ snap list
Name               Version                     Rev    Tracking         Publisher              Notes
bitcoin-core       0.20.1                      81     latest/stable    bitcoin-core           -
chromium           86.0.4240.198               1399   latest/stable    canonical✓             -
codium             1.51.1                      107    latest/stable    snapcrafters           classic
core               16-2.47.1                   10185  latest/stable    canonical✓             core
core18             20200929                    1932   latest/stable    canonical✓             base
docker             19.03.11                    471    latest/stable    canonical✓             -
electrum           2.6.4-tpaw0                 2      latest/stable    antonwilc0x            -
gnome-3-28-1804    3.28.0-19-g98f9e67.98f9e67  145    latest/stable    canonical✓             -
gnome-3-34-1804    0+git.3556cb3               60     latest/stable/…  canonical✓             -
gtk-common-themes  0.1-36-gc75f853             1506   latest/stable/…  canonical✓             -
postgresql10       10.4                        47     latest/stable    cmd✓                   -
powershell         7.1.0                       149    latest/stable    microsoft-powershell✓  classic
snap-store         3.36.0-82-g80486d0          481    latest/stable/…  canonical✓             -
snapd              2.47.1                      9721   latest/stable    canonical✓             snapd
nicholas@mordor:~$ 

答案1

简单的足够的

postgres@mordor:~$ 
postgres@mordor:~$ snap info postgresql10
name:      postgresql10
summary:   PostgreSQL is a powerful, open source object-relational database system.
publisher: Command Prompt, Inc. (cmd✓)
store-url: https://snapcraft.io/postgresql10
license:   unset
description: |
  PostgreSQL is a powerful, open source object-relational database system. It has more than 15 years
  of active development and a proven architecture that has earned it a strong reputation for
  reliability, data integrity, and correctness.
commands:
  - postgresql10.clusterdb
  - postgresql10.createdb
  - postgresql10.createuser
  - postgresql10.dropdb
  - postgresql10.dropuser
  - postgresql10.ecpg
  - postgresql10.initdb
  - postgresql10.initialize
  - postgresql10.oid2name
  - postgresql10.pgarchivecleanup
  - postgresql10.pgbasebackup
  - postgresql10.pgbench
  - postgresql10.pgconfig
  - postgresql10.pgcontroldata
  - postgresql10.pgctl
  - postgresql10.pgdump
  - postgresql10.pgdumpall
  - postgresql10.pgisready
  - postgresql10.pgreceivewal
  - postgresql10.pgrecvlogical
  - postgresql10.pgresetwal
  - postgresql10.pgrestore
  - postgresql10.pgrewind
  - postgresql10.pgtestfsync
  - postgresql10.pgtesttiming
  - postgresql10.pgupgrade
  - postgresql10.pgwaldump
  - postgresql10.postgres
  - postgresql10.postmaster
  - postgresql10.psql
  - postgresql10.reindexdb
  - postgresql10.vacuumdb
  - postgresql10.vacuumlo
snap-id:      W7TagWOq55vJphD3Ek4ZUtQytGRMeQqK
tracking:     latest/stable
refresh-date: today at 16:16 PST
channels:
  latest/stable:    10.4 2018-05-11 (47) 40MB -
  latest/candidate: ↑                         
  latest/beta:      ↑                         
  latest/edge:      ↑                         
installed:          10.4            (47) 40MB -
postgres@mordor:~$ 
postgres@mordor:~$ postgresql10.psql
psql (10.4)
Type "help" for help.

postgres=# 
postgres=# exit
postgres-# quit
postgres-# /quit
postgres-# help
postgres-# "help"
postgres-# ^C
postgres=# 

虽然我不能弄清楚如何退出。

相关内容