Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3a3a2e5

Browse files
committed
Merge branch 'PGPROEE10' of gitlab.postgrespro.ru:pgpro-dev/postgrespro into PGPROEE10
2 parents 1a30a1d + 2eec2a8 commit 3a3a2e5

File tree

2 files changed

+119
-24
lines changed

2 files changed

+119
-24
lines changed

doc/src/sgml/in-memory.sgml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,22 @@
1616
<para>
1717
Fast random access on the primary key.
1818
This can result in significant performance benefits when
19-
working with data that has to be moved to RAM and requires
20-
a very high read and write access rate,
21-
especially on multi-core systems.
19+
working with data that requires a very high read and write
20+
access rate, especially on multi-core systems.
2221
</para>
2322
</listitem>
2423
<listitem>
2524
<para>
26-
Saving disk space: there is no primary key
27-
duplication as all data is stored directly in the index.
25+
Effective space usage.
26+
There is no primary key duplication as all data
27+
is stored directly in the index.
2828
</para>
2929
</listitem>
3030
</itemizedlist>
3131
</para>
3232

3333
<para>
34-
Just like regular heap-organized tables,
35-
in-memory tables support transactions, including savepoints.
34+
In-memory tables support transactions, including savepoints.
3635
However, the data in such tables is stored only while the server is running.
3736
Once the server is shut down, all in-memory data gets truncated.
3837
When using in-memory tables, you should also take into account the following
@@ -202,20 +201,20 @@ OPTIONS (INDICES '(id, author COLLATE "ru_RU" ASC)');
202201
Fill the <structname>blog_views</structname>
203202
table with initial zero values for initial ten blog posts:
204203
<programlisting>
205-
# INSERT INTO blog_views (SELECT id, 0 FROM generate_series(1, 10) AS id);
204+
postgres=# INSERT INTO blog_views (SELECT id, 0 FROM generate_series(1, 10) AS id);
206205
</programlisting>
207206
</para>
208207

209208
<para>Increment the view count for a couple of posts
210209
and display the result:
211210
<programlisting>
212-
# UPDATE blog_views SET views = views + 1 WHERE id = 1;
211+
postgres=# UPDATE blog_views SET views = views + 1 WHERE id = 1;
213212
UPDATE 1
214-
# UPDATE blog_views SET views = views + 1 WHERE id = 1;
213+
postgres=# UPDATE blog_views SET views = views + 1 WHERE id = 1;
215214
UPDATE 2
216-
# UPDATE blog_views SET views = views + 1 WHERE id = 2;
215+
postgres=# UPDATE blog_views SET views = views + 1 WHERE id = 2;
217216
UPDATE 1
218-
# SELECT * FROM blog_views WHERE id = 1 OR id = 2;
217+
postgres=# SELECT * FROM blog_views WHERE id = 1 OR id = 2;
219218
id | views
220219
----+-------
221220
1 | 2
@@ -227,7 +226,7 @@ UPDATE 1
227226
Check planning and execution costs for a query that
228227
only requires a primary key lookup:
229228
<programlisting>
230-
# EXPLAIN ANALYZE SELECT * FROM blog_views WHERE id = 1;
229+
postgres=# EXPLAIN ANALYZE SELECT * FROM blog_views WHERE id = 1;
231230
QUERY PLAN
232231
-------------------------------------------------------------------
233232
Foreign Scan on blog_views (cost=0.02..0.03 rows=1 width=16)
@@ -242,7 +241,7 @@ Execution time: 0.035 ms
242241
Check the costs of calculating the sum of all views, which requires
243242
a full index scan:
244243
<programlisting>
245-
# EXPLAIN ANALYZE SELECT SUM(views) FROM blog_views;
244+
postgres=# EXPLAIN ANALYZE SELECT SUM(views) FROM blog_views;
246245
QUERY PLAN
247246
--------------------------------------------------------------------
248247
Aggregate (cost=1.62..1.63 rows=1 width=32)
@@ -319,7 +318,7 @@ Execution time: 0.353 ms
319318
as well as the total number of pages allocated for in-memory tables.
320319
For example:
321320
<screen>
322-
# SELECT * FROM in_memory.in_memory_page_stats();
321+
postgres=# SELECT * FROM in_memory.in_memory_page_stats();
323322
used_pages | free_pages | all_pages
324323
------------+------------+-----------
325324
576 | 7616 | 8192

doc/src/sgml/multimaster.sgml

Lines changed: 105 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<listitem>
7575
<para>
7676
<filename>multimaster</filename> can only replicate one database
77-
per cluster, which is specified in the <varname>multimaster.conn_strings</varname> variable. If you connect to a different database,
77+
per cluster. This database must be specified in the <varname>multimaster.conn_strings</varname> variable. If you connect to a different database,
7878
all operations will fail with the corresponding error message.
7979
</para>
8080
</listitem>
@@ -375,6 +375,16 @@ where <replaceable>datadir</> is the directory containing the database cluster.
375375
cluster node:
376376
</para>
377377
<orderedlist>
378+
<listitem>
379+
<para>
380+
Allow replication of the <literal>mydb</literal> database
381+
to each cluster node on behalf of <literal>myuser</literal>,
382+
as explained in <xref linkend="auth-pg-hba-conf">.
383+
Make sure to use the
384+
<link linkend="auth-methods">authentication method</link> that
385+
satisfies your security requirements.
386+
</para>
387+
</listitem>
378388
<listitem>
379389
<para>
380390
Modify the <filename>postgresql.conf</filename> configuration
@@ -460,7 +470,6 @@ multimaster.conn_strings = 'dbname=mydb user=myuser host=node1,dbname=mydb user=
460470
</para>
461471
<para>In most cases, three cluster nodes are enough to ensure high availability. Since the data on all cluster nodes is the same, you do not typically need more than five cluster nodes.
462472
</para>
463-
<para>If you would like to change the default connection settings for a cluster node, you can add other <link linkend="libpq-paramkeywords"> connection parameters</link> to the corresponding connection string in the <varname>multimaster.conn_strings</varname> variable. If you change the default port on which the arbiter process listens for connections, you must specify this port in the <literal>arbiter_port</literal> parameter. For details, see <xref linkend="multimaster-arbiter-port"> and <xref linkend="multimaster-conn-strings">.</para>
464473
<important><para>The
465474
<literal>multimaster.node_id</literal> variable takes natural
466475
numbers starting from 1, without any gaps in numbering.
@@ -470,8 +479,30 @@ multimaster.conn_strings = 'dbname=mydb user=myuser host=node1,dbname=mydb user=
470479
list the nodes in the order of their IDs. The
471480
<literal>multimaster.conn_strings</literal> variable must be the
472481
same on all nodes.</para></important>
473-
474-
</listitem>
482+
<para>
483+
You can customize connection parameters by adding other
484+
<link linkend="libpq-paramkeywords">libpq connection options</link>
485+
to connection strings in the <varname>multimaster.conn_strings</varname>
486+
variable. By default, <filename>multimaster</filename> uses ports 5432
487+
and 5433 to establish connections between the nodes and for the arbiter
488+
process to listen for connections, respectively. If these ports are
489+
already in use, you must specify other ports by adding
490+
<literal>port</literal> and <literal>arbiter_port</literal> options
491+
to each connection string in the <varname>multimaster.conn_strings</varname>
492+
variable. To check whether the default ports are available, you can run with the following command:
493+
<programlisting>
494+
netstat -ln | grep -E '5432|5433'
495+
</programlisting>
496+
Make sure these ports are not blocked by firewall.
497+
</para>
498+
<para>
499+
If you change the <literal>arbiter_port</literal>
500+
option, you must also specify this port in the
501+
<literal>multimaster.arbiter_port</literal> variable. For details,
502+
see <xref linkend="multimaster-arbiter-port"> and
503+
<xref linkend="multimaster-conn-strings">.
504+
</para>
505+
</listitem>
475506
</itemizedlist>
476507
<para>
477508
Depending on your network environment and usage patterns, you
@@ -480,11 +511,6 @@ multimaster.conn_strings = 'dbname=mydb user=myuser host=node1,dbname=mydb user=
480511
<xref linkend="multimaster-tuning-configuration-parameters">.
481512
</para>
482513
</listitem>
483-
<listitem>
484-
<para>
485-
Modify the <filename>pg_hba.conf</filename> file to allow replication to each cluster node on behalf of <literal>myuser</literal>.
486-
</para>
487-
</listitem>
488514
<listitem>
489515
<para>
490516
Restart <productname>PostgreSQL</productname>:
@@ -515,6 +541,76 @@ SELECT mtm.get_cluster_state();
515541
<para><emphasis role="strong">See Also</emphasis></para>
516542
<para><link linkend="multimaster-tuning-configuration-parameters">Tuning
517543
Configuration Parameters</link></para>
544+
<sect4>
545+
<title>Sample Cluster Configuration</title>
546+
<para>
547+
This section shows a sample configuration of a three-node cluster for the
548+
<literal>myuser</literal> user and <literal>mydb</literal> database.
549+
</para>
550+
<para>
551+
First, run the following commands on all cluster nodes:
552+
<programlisting>
553+
# Switch to the 'postgres' user
554+
sudo su - postgres
555+
556+
# Set up environment variables
557+
export PGHOME=/usr/pgproee-&majorversion;
558+
export PATH=$PGHOME/bin:$PATH
559+
export MANPATH=$PGHOME/share/man:$MANPATH
560+
export PGDATA=/var/lib/pgproee/&majorversion;/data
561+
562+
# Create a new user 'myuser' with superuser priviledges
563+
psql --dbname=postgres --username=postgres -c "CREATE USER myuser WITH SUPERUSER ENCRYPTED PASSWORD 'myuserpassword'"
564+
565+
# Create a new database 'mydb'
566+
psql --dbname=postgres --username=myuser --host=127.0.0.1 -c "CREATE DATABASE mydb"
567+
568+
# Enable replication on all cluster nodes.
569+
# The 'trust' method in this example is only provided for
570+
# illustration purposes and is not recommended on production systems.
571+
sed -i '/md5$/s|host|#host|' $PGDATA/pg_hba.conf
572+
echo "host replication myuser samenet trust" >> $PGDATA/pg_hba.conf
573+
echo "host all all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf
574+
575+
# Configure postgresql.conf settings
576+
echo "multimaster.max_nodes = 3" >> $PGDATA/postgresql.conf
577+
echo "multimaster.node_id = 'hostname | '{ print substr($1,5,1) }''" >> $PGDATA/postgresql.conf
578+
echo "multimaster.conn_strings = 'dbname=mydb user=myuser host=node1,dbname=mydb user=myuser host=node2,dbname=mydb user=myuser host=node3'" >> $PGDATA/postgresql.conf
579+
psql --dbname=mydb --username=myuser --host=127.0.0.1 -c "ALTER SYSTEM SET default_transaction_isolation TO 'read committed'"
580+
psql --dbname=mydb --username=myuser --host=127.0.0.1 -c "ALTER SYSTEM SET wal_level TO logical"
581+
psql --dbname=mydb --username=myuser --host=127.0.0.1 -c "ALTER SYSTEM SET max_connections TO 100"
582+
psql --dbname=mydb --username=myuser --host=127.0.0.1 -c "ALTER SYSTEM SET max_prepared_transactions to 300"
583+
psql --dbname=mydb --username=myuser --host=127.0.0.1 -c "ALTER SYSTEM SET max_wal_senders TO 10"
584+
psql --dbname=mydb --username=myuser --host=127.0.0.1 -c "ALTER SYSTEM SET max_replication_slots TO 10"
585+
psql --dbname=mydb --username=myuser --host=127.0.0.1 -c "ALTER SYSTEM SET max_worker_processes TO 250"
586+
psql --dbname=mydb --username=myuser --host=127.0.0.1 -c "ALTER SYSTEM SET shared_preload_libraries TO multimaster"
587+
psql --exit
588+
589+
# Restart &productname;
590+
sudo systemctl restart postgrespro-enterprise-&majorversion;.service
591+
</programlisting>
592+
</para>
593+
<para>
594+
Now create the <filename>multimaster</filename> extension on one of the nodes.
595+
It will be replicated to all the other cluster nodes automatically.
596+
<programlisting>
597+
# Switch to the 'postgres' user
598+
sudo su - postgres
599+
600+
# Set up environment variables
601+
export PGHOME=/usr/pgproee-&majorversion;
602+
export PATH=$PGHOME/bin:$PATH
603+
export MANPATH=$PGHOME/share/man:$MANPATH
604+
export PGDATA=/var/lib/pgproee/&majorversion;/data
605+
606+
# Create multimaster extension on one of the nodes
607+
psql --dbname=mydb --username=myuser --host=127.0.0.1 -c "CREATE EXTENSION IF NOT EXISTS multimaster"
608+
</programlisting>
609+
</para>
610+
<para>
611+
The cluster is set up and ready to use.
612+
</para>
613+
</sect4>
518614
</sect3>
519615
<sect3 id="multimaster-tuning-configuration-parameters">
520616
<title>Tuning Configuration Parameters</title>

0 commit comments

Comments
 (0)