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

В YMatrix 6 мы предоставляем инструменты эксплуатации и обслуживания кластера: mxstart, mxstop и mxstate.

Примечание!
Вышеуказанные инструменты эксплуатации и обслуживания впервые представлены в YMatrix 5. Дополнительную информацию об архитектуре YMatrix 5 см. в разделе Архитектура YMatrix 5.
В YMatrix 4 (MatrixDB 4) по умолчанию используются инструменты эксплуатации и обслуживания серии Greenplum. Подробности см. в разделе Основное управление кластером YMatrix 4.

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

1.1 Запуск

mxstart -a  # Start the cluster

1.2 Остановка

mxstop -a   # Stop the cluster (the shutdown will hang if active sessions exist)
mxstop -a -M fast  # Quickly stop the cluster using fast mode

1.3 Перезапуск

mxstop -ar # Restart the cluster, wait for currently running SQL to finish (will hang if active sessions exist)
mxstop -ar -M fast # Quickly restart the cluster using fast mode

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

mxstop -u  # Reload configuration files

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

mxstate     # Display cluster status
mxstate -s  # Display the overall status of the YMatrix cluster
mxstate -m  # List mirrors
mxstate -f  # Display Standby Master information

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

Показать значение конфигурации:

gpconfig -s {GUC}

# Example: Check maximum connection limit
gpconfig -s max_connections

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

gpconfig -c {GUC} -v {Value} -m {Value}  # -m sets the value on master, -v sets the value on segments
gpconfig -c {GUC} -v {Value}             # If -m is omitted, master uses the same value as segments

# Examples:
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 по умолчанию:

# Edit the profile to set defaults
vi ~/.bash_profile  # As mxadmin user, add the following variables

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

Немедленно примените изменения:

source ~/.bash_profile

Повторно подключитесь с помощью psql:

# Now psql connects with default settings
psql
# Equivalent to:
psql -d postgres -U mxadmin -h localhost -p 5432

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

\l                    List all databases.
\d                    List all tables, views, and sequences in the current database.
\d [table_name]       Describe the structure of a specific table.
\dt                   Show only matching tables.
\di                   Show only indexes.
\dt+ table_name       Show table size.
\di+ index_name       Show index size.
\ds                   Show only sequences.
\dv                   Show only views.
\dm                   List materialized views.
\df                   Show only functions.
\dn                   List all schemas.
\du or \dg            List all roles or users.
\dp table_name        \z table_name Display access privileges for a table.
\dx                   Show installed extensions.
\sf function_name     Show function definition.
\h                    Show help for SQL commands, e.g., \h select.
\?                    List all psql meta-commands.
\c                    Display current database and connection info.
\c [database_name]    Connect to another database.
\e                    Open text editor for command editing.
\x                    Toggle expanded output mode for query results.
\!                    Execute operating system commands.
\o /home/postgres/test.txt  Save query output to file; disable with \o.
\drds                 List per-database or per-user configuration settings.
\s                    Show command history.
\watch 1              Re-execute previous command every 1 second.

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

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

Способ 1: Используйте утилиту createdb:

createdb test

Способ 2: Используйте SQL-команду:

psql postgres
postgres=# CREATE DATABASE test;

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

Способ 1: Используйте утилиту dropdb:

dropdb test

Способ 2: Используйте SQL-команду:

psql postgres
postgres=# DROP DATABASE test;