Основное управление кластером

YMatrix 5 представляет совершенно новую архитектуру базы данных. В рамках этой архитектуры мы также предоставляем новейшие инструменты эксплуатации и обслуживания: mxstart, mxstop, mxstate. Дополнительную информацию об архитектуре YMatrix 5 см. в разделе Архитектура YMatrix.

Примечание!
По умолчанию YMatrix 5 использует новые инструменты эксплуатации и обслуживания для управления кластером, тогда как YMatrix 4 (MatrixDB 4) по-прежнему использует инструменты обслуживания серии Greenplum. Подробности см. в разделе Базовое управление кластером YMatrix 4.

1. Управление кластером

1.1 Запуск

mxstart -a  # Start the cluster

1.2 Остановка

mxstop -a   # Stop the cluster (may hang if sessions are connected)
mxstop -a -M fast  # Fast - mode shutdown

1.3 Перезапуск

mxstop -ar # Restart, waiting for ongoing SQL to finish (may hang if sessions are connected)
mxstop -ar -M fast # Fast - mode restart

1.4 Перезагрузка конфигурации

mxstop -u  # Reload configuration files

1.5 Проверка состояния кластера

mxstate     # Check cluster status
mxstate -s  # Check the entire YMatrix cluster's status
mxstate -m  # List Mirrors
mxstate -f  # Show Standby Master info

1.6 Просмотр и изменение параметров конфигурации

Отображение значений конфигурации:

gpconfig -s {GUC}

# Example: Check the maximum number of connections allowed
gpconfig -s max_connections

Изменение значения конфигурации:

ggpconfig -c {GUC} -v {Value} -m {Value} # -m for Master, -v for Segment
gpconfig -c {GUC} -v {Value} # Same value for Master and Segment

# example:
gpconfig -c max_connections -v 1000 -m 300
gpconfig -c shared_buffers -v 2GB

2. Вход в кластер

2.1 Вход в базу данных через psql

psql -d ${db_name} -U ${user_name} -h ${ip_addr} -p ${port}

Изменение переменных окружения и добавление значений по умолчанию для psql:

# You can modify the default value by modifying the environment variables
vi ~/.bash_profile  # Edit with mxadmin user, add variables:

export PGPORT=5432   # Default port
export PGUSER=mxadmin # Default user
export PGDATABASE=postgres  # Default database

Немедленное применение переменных окружения:

source ~/.bash_profile

Повторный вход в базу данных с помощью SQL:

# Execute psql to log in to the database
psql
# The default value at this time is
psql -d postgres -U mxadmin -h localhost -p 5432

2.2 Метакоманды psql

\l List all databases. 
\d List tables, views, sequences in the current database 
\d [table_name] Show table structure
\dt Show matching tables.
\di Show indexes.
\dt+ table_name Check table size.
\di+ index_name Check index size.
\ds Show sequences.
\dv Show views.
\dm Show materialized views.
\df Show functions.
\dn List schemas.
\du or \dg List roles/users.
\dp or \z Show table permissions.
\dx Show extension info.
\sf function_name Show function code.
\h Show SQL command explanation.
\? List psql commands. 
\c Show current DB and connection info.
\c [database_name] Connect to another DB. 
\e Open text editor. 
\x Set query result output
\! Execute OS command
\o /home/postgres/test.txt Save results to file (close with \o)
\drds Show RDS - related info
\s Show history
\watch 1 Repeat last command every 1 second

3. Создание и удаление баз данных

3.1 Создание базы данных

Способ 1: создание с помощью утилиты createdb:

createdb test

Способ 2: создание с помощью SQL-оператора CREATE DATABASE:

psql postgres
postgres=# create database test;

3.2 Удаление базы данных

Способ 1: удаление с помощью утилиты dropdb:

dropdb test

Способ 2: удаление с помощью SQL-оператора DROP DATABASE:

psql postgres
postgres=# drop database test;