74
74
<listitem>
75
75
<para>
76
76
<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,
78
78
all operations will fail with the corresponding error message.
79
79
</para>
80
80
</listitem>
@@ -375,6 +375,16 @@ where <replaceable>datadir</> is the directory containing the database cluster.
375
375
cluster node:
376
376
</para>
377
377
<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>
378
388
<listitem>
379
389
<para>
380
390
Modify the <filename>postgresql.conf</filename> configuration
@@ -460,7 +470,6 @@ multimaster.conn_strings = 'dbname=mydb user=myuser host=node1,dbname=mydb user=
460
470
</para>
461
471
<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.
462
472
</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>
464
473
<important><para>The
465
474
<literal>multimaster.node_id</literal> variable takes natural
466
475
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=
470
479
list the nodes in the order of their IDs. The
471
480
<literal>multimaster.conn_strings</literal> variable must be the
472
481
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>
475
506
</itemizedlist>
476
507
<para>
477
508
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=
480
511
<xref linkend="multimaster-tuning-configuration-parameters">.
481
512
</para>
482
513
</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>
488
514
<listitem>
489
515
<para>
490
516
Restart <productname>PostgreSQL</productname>:
@@ -515,6 +541,76 @@ SELECT mtm.get_cluster_state();
515
541
<para><emphasis role="strong">See Also</emphasis></para>
516
542
<para><link linkend="multimaster-tuning-configuration-parameters">Tuning
517
543
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>
518
614
</sect3>
519
615
<sect3 id="multimaster-tuning-configuration-parameters">
520
616
<title>Tuning Configuration Parameters</title>
0 commit comments