Установка PostgreSQL в Ubuntu

Содержание статьи
Установка из репозитория Ubuntu
Установка самой свежей версии
Подключение к PostgreSQL

Установка из репозитория Ubuntu

apt -a show postgresql

Package: postgresql Version: 12+214ubuntu0.1 Priority: optional Section: database Source: postgresql-common (214ubuntu0.1) Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Debian PostgreSQL Maintainers <team+postgresql@tracker.debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 67.6 kB Depends: postgresql-12 Suggests: postgresql-doc Task: postgresql-server Download-Size: 3,924 B APT-Sources: http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages Description: object-relational SQL database (supported version) This metapackage always depends on the currently supported PostgreSQL database server version. . PostgreSQL is a fully featured object-relational database management system. It supports a large part of the SQL standard and is designed to be extensible by users in many aspects. Some of the features are: ACID transactions, foreign keys, views, sequences, subqueries, triggers, user-defined types and functions, outer joins, multiversion concurrency control. Graphical user interfaces and bindings for many programming languages are available as well. N: There is 1 additional record. Please use the '-a' switch to see it

sudo apt install postgresql postgresql-contrib

Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: distro-info Use 'sudo apt autoremove' to remove it. The following additional packages will be installed: libllvm10 libpq5 postgresql-12 postgresql-client-12 postgresql-client-common postgresql-common sysstat Suggested packages: postgresql-doc postgresql-doc-12 libjson-perl isag The following NEW packages will be installed: libllvm10 libpq5 postgresql postgresql-12 postgresql-client-12 postgresql-client-common postgresql-common postgresql-contrib sysstat 0 upgraded, 9 newly installed, 0 to remove and 74 not upgraded. Need to get 30.6 MB of archives. After this operation, 121 MB of additional disk space will be used. Do you want to continue? [Y/n]

Y

Get:1 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libllvm10 amd64 1:10.0.0-4ubuntu1 [15.3 MB] Get:2 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 libpq5 amd64 12.7-0ubuntu0.20.04.1 [116 kB] Get:3 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 postgresql-client-common all 214ubuntu0.1 [28.2 kB] Get:4 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 postgresql-client-12 amd64 12.7-0ubuntu0.20.04.1 [1,045 kB] Get:5 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 postgresql-common all 214ubuntu0.1 [169 kB] Get:6 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 postgresql-12 amd64 12.7-0ubuntu0.20.04.1 [13.5 MB] Get:7 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 postgresql all 12+214ubuntu0.1 [3,924 B] Get:8 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 postgresql-contrib all 12+214ubuntu0.1 [3,932 B] Get:9 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 sysstat amd64 12.2.0-2 [453 kB] Fetched 30.6 MB in 5s (6,331 kB/s) Preconfiguring packages ... Selecting previously unselected package libllvm10:amd64. (Reading database ... 344555 files and directories currently installed.) Preparing to unpack .../0-libllvm10_1%3a10.0.0-4ubuntu1_amd64.deb ... Unpacking libllvm10:amd64 (1:10.0.0-4ubuntu1) ... Selecting previously unselected package libpq5:amd64. Preparing to unpack .../1-libpq5_12.7-0ubuntu0.20.04.1_amd64.deb ... Unpacking libpq5:amd64 (12.7-0ubuntu0.20.04.1) ... Selecting previously unselected package postgresql-client-common. Preparing to unpack .../2-postgresql-client-common_214ubuntu0.1_all.deb ... Unpacking postgresql-client-common (214ubuntu0.1) ... Selecting previously unselected package postgresql-client-12. Preparing to unpack .../3-postgresql-client-12_12.7-0ubuntu0.20.04.1_amd64.deb ... Unpacking postgresql-client-12 (12.7-0ubuntu0.20.04.1) ... Selecting previously unselected package postgresql-common. Preparing to unpack .../4-postgresql-common_214ubuntu0.1_all.deb ... Adding 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common' Unpacking postgresql-common (214ubuntu0.1) ... Selecting previously unselected package postgresql-12. Preparing to unpack .../5-postgresql-12_12.7-0ubuntu0.20.04.1_amd64.deb ... Unpacking postgresql-12 (12.7-0ubuntu0.20.04.1) ... Selecting previously unselected package postgresql. Preparing to unpack .../6-postgresql_12+214ubuntu0.1_all.deb ... Unpacking postgresql (12+214ubuntu0.1) ... Selecting previously unselected package postgresql-contrib. Preparing to unpack .../7-postgresql-contrib_12+214ubuntu0.1_all.deb ... Unpacking postgresql-contrib (12+214ubuntu0.1) ... Selecting previously unselected package sysstat. Preparing to unpack .../8-sysstat_12.2.0-2_amd64.deb ... Unpacking sysstat (12.2.0-2) ... Setting up postgresql-client-common (214ubuntu0.1) ... Setting up libpq5:amd64 (12.7-0ubuntu0.20.04.1) ... Setting up libllvm10:amd64 (1:10.0.0-4ubuntu1) ... Setting up postgresql-client-12 (12.7-0ubuntu0.20.04.1) ... update-alternatives: using /usr/share/postgresql/12/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1. gz (psql.1.gz) in auto mode Setting up postgresql-common (214ubuntu0.1) ... Adding user postgres to group ssl-cert Creating config file /etc/postgresql-common/createcluster.conf with new version Building PostgreSQL dictionaries from installed myspell/hunspell packages... en_us Removing obsolete dictionary files: Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgres ql.service. Setting up postgresql-12 (12.7-0ubuntu0.20.04.1) ... Creating new PostgreSQL cluster 12/main ... /usr/lib/postgresql/12/bin/initdb -D /var/lib/postgresql/12/main --auth-local peer --auth-host md5 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 locales COLLATE: en_US.UTF-8 CTYPE: en_US.UTF-8 MESSAGES: en_US.UTF-8 MONETARY: en_GB.UTF-8 NUMERIC: en_GB.UTF-8 TIME: en_GB.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 /var/lib/postgresql/12/main ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... Europe/Helsinki creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok Success. You can now start the database server using: pg_ctlcluster 12 main start Ver Cluster Port Status Owner Data directory Log file 12 main 5432 down postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log update-alternatives: using /usr/share/postgresql/12/man/man1/postmaster.1.gz to provide /usr/share/man/man1/p ostmaster.1.gz (postmaster.1.gz) in auto mode Setting up sysstat (12.2.0-2) ... Creating config file /etc/default/sysstat with new version update-alternatives: using /usr/bin/sar.sysstat to provide /usr/bin/sar (sar) in auto mode Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /lib/systemd/system/sysstat.ser vice. Setting up postgresql-contrib (12+214ubuntu0.1) ... Setting up postgresql (12+214ubuntu0.1) ... Processing triggers for systemd (245.4-4ubuntu3.6) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9.2) ...

Установка новейшей версии

Подключение к PostgreSQL

sudo su - postgres

psql

psql (12.7 (Ubuntu 12.7-0ubuntu0.20.04.1)) Type "help" for help. postgres=#

Получить данные о подключении

\conninfo

You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".

Установка pgAdmin

Установить публичный ключ

sudo curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add

Создать файл конфигурации репозитория

sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'

Установить и десктопную и веб версии:

sudo apt install pgadmin4

Установить только десктопную версию

sudo apt install pgadmin4-desktop

Установить только веб версию

sudo apt install pgadmin4-web

Настроить веб серве для веб версию

sudo /usr/pgadmin4/bin/setup-web.sh

Веб версию можно открыть в браузере

http://127.0.0.1/pgadmin4

Поиск по сайту

Контакты и сотрудничество:
Рекомендую наш хостинг beget.ru
Пишите на info@urn.su если Вы:
1. Хотите написать статью для нашего сайта или перевести статью на свой родной язык.
2. Хотите разместить на сайте рекламу, подходящуюю по тематике.
3. Реклама на моём сайте имеет максимальный уровень цензуры. Если Вы увидели рекламный блок недопустимый для просмотра детьми школьного возраста, вызывающий шок или вводящий в заблуждение - пожалуйста свяжитесь с нами по электронной почте
4. Нашли на сайте ошибку, неточности, баг и т.д. ... .......
5. Статьи можно расшарить в соцсетях, нажав на иконку сети: