Использовался VB 5.2 и образ Linux 7.0 Developer Day MV.
Используя root:
Запускаем psql и видим список имеющихся БД:
Используя root:
Install the repository RPM: # yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-1.noarch.rpm Install the client packages: # yum install postgresql10 Optionally install the server packages: # yum install postgresql10-server Optionally initialize the database and enable automatic start: # /usr/pgsql-10/bin/postgresql-10-setup initdb # systemctl enable postgresql-10 # systemctl start postgresql-10Используем роль postgres :
[oracle@localhost ~]$ sudo su - postgresПолезная ссылка о командах выше.
Запускаем psql и видим список имеющихся БД:
-bash-4.2$ psql psql (10.1) Type "help" for help. postgres=# \list List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgresСоздаем тестовую БД и проверяем подключение:
1) -bash-4.2$ createdb xendb -bash-4.2$ psql xendb version: xendb=# select version();Для информации. Чем отличается подключение под супер-пользователем в консоли?
user: mydb=> The last line could also be: mydb=# That would mean you are a database superuser, which is most likely the case if you installed the PostgreSQL instance yourself. Being a superuser means that you are not subject to access controls.Далее:
create role: xendb=# CREATE ROLE xen WITH NOSUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION NOBYPASSRLS PASSWORD 'xen'; List of roles: xendb=# \du drop db and create again: -bash-4.2$ dropdb xendb -bash-4.2$ createdb xendb --owner=xen -bash-4.2$ psql postgres=# \list List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- xendb | xen | UTF8 | en_US.UTF-8 | en_US.UTF-8 |Настройки подключения. Необходим root.
# find / -name pg_hba.conf /var/lib/pgsql/10/data/pg_hba.conf #vim pg_hba.conf Then change: for "local" change method 'peer' on 'trust' add line: host all all 0.0.0.0/0 md5 Example: # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 ident host all all 0.0.0.0/0 md5 # IPv6 local connections: host all all ::1/128 ident # Allow replication connections from localhost, by a user with the # replication privilege. local replication all peer host replication all 127.0.0.1/32 ident host replication all ::1/128 identЗатем необходимо перестартовать postgres (два варианта)
1) # systemctl stop postgresql-10 # systemctl start postgresql-10 2) postgres=# select pg_reload_conf(); check: -bash-4.2$ psql -U xen xendbДля первого знакомства с СУБД подойдут готовые скрипты из исходников. Скрипт basic.sql. Я использовал пользователя oracle для этого.
Install git and clone source distribution $ cd ..src/tutorial $ sudo yum install postgresql-devel $ make $ sudo su - postgres -bash-4.2$ cd ../src/tutorial/ -bash-4.2$ psql -U xen xendb xendb=> \i basics.sqlЕсли вы хотите подключиться к БД на VB c хоста, то необходимо настроить подключение. telnet с хоста по порту 5432 не проходит.
[oracle@localhost ~]$ sudo netstat -tanp | grep 5432 tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1041/postmaster Listen only localhost. edit: [oracle@localhost ~]$ sudo netstat -tanp | grep 5432 [root@localhost ~]# cd /var/lib/pgsql/10/data [root@localhost data]# vim postgresql.conf change line: listen_addresses = 'localhost' # what IP address(es) to listen on; to listen_addresses = '*' # what IP address(es) to listen on;И последнее, если не использовать Public схему, то ниже способ как переключиться в нужную схему:
Create schema: $ create schema xen; xendb=> show search_path; search_path ----------------- "$user", public xendb=> set search_path to xen; xendb=> show search_path; search_path ------------- xen
Комментариев нет:
Отправить комментарий