Completed draft to update to F43 and added PostgreSQL Cheat Sheet version 1

This commit is contained in:
Peter Boy 2025-12-06 18:47:54 +01:00
commit 873692c967
3 changed files with 84 additions and 56 deletions

View file

@ -24,6 +24,7 @@
* Providing services
** xref:services/postgresql-setup.adoc[Setting up PostgreSQL Database Server]
** xref:services/fedsysadmins-cheatsheet-postgresql.adoc[Fedora System Administrator's Cheat Sheet: PostgreSQL]
** xref:services/httpd-basic-setup.adoc[Setting up a basic web server]
** xref:services/filesharing-nfs-installation.adoc[File sharing with NFS Installation]

View file

@ -0,0 +1,59 @@
= Fedora System Administrators Cheat Sheet PostgreSQL
Peter Boy
:page-authors: {author}
:revnumber: F35-F43
:revdate: 2025-12-04
[abstract]
The Fedora System Administrator's Cheat Sheet series compiles typical, frequently used instructions for various application programs, most of which can be used with minor modifications via copy&paste. They also contain direct links to the relevant sections of the upstream documentation.
==== Basic Commands
Get administrative access to a postgresql database and get a postgres terminal prompt::
+
----
[...]# sudo -i -u postgres psql
psql (18.1)
Type "help" for help.
postgres=#
----
List all databases::
+
----
postgres=# \l
----
Connect to a database::
+
----
postgres=# \c <database_name_from_above_list>
----
List all tables in the database connected to::
+
----
postgres=# \dt
----
List all users / roles::
+
----
postgres=# \du
----
Create a new user / role::
+
----
postgres=# CREATE USER new_user_name WITH PASSWORD 'password';
----
Change password of a user / role::
+
----
postgres=# ALTER USER user_name WITH PASSWORD 'new_password';
----

View file

@ -22,7 +22,7 @@ Postgresql is the recommended database management system of Fedora. It is a key
// *Status of this document*: Updated to f41.
//====
Fedora 43 includes PostgreSQL 18.1 If you update from F42, read the release notes or the xref:index.adoc#updating-f43[update description on Server home page] for detailed instructions.
Fedora 43 includes PostgreSQL 18.1 If you update from F42, read the release notes or the xref:index.adoc#_updating_to_fedora_43[update description on Server home page] for detailed instructions.
== 1. Storage preparation
@ -30,7 +30,7 @@ In Fedora, PostgreSQL stores the databases and other runtime files in the `/var/
Following the Fedora storage concept, a dedicated file system on a logical volume, mounted at the appropriate position in the directory tree, takes over this function.
A convenient descriptive name for both the logical volume and the file system is `pgsql`. The volume group that contains the logical volume is called `fedora_fedora` in a default installation. A suitable initial size is likely to be 50 GiB in many cases.
A convenient descriptive name for both the logical volume and the file system is `pgsql`. The volume group that contains the logical volume is called `fedora` or `systemVG` in a default installation. A suitable initial size is likely to be 50 GiB in many cases.
In any case, the system administrator must adapt the following command sequence according to the local requirements! With a Linux LVM and Software raid, XFS can autonomously determine its optimal configuration values. With some hardware raids, intervention by the administrator can also be useful for this.
@ -85,15 +85,14 @@ The installer should have adjusted all SELinux labels in the pgsql directory alr
-rw-r--r--. 1 postgres postgres system_u:object_r:postgresql_db_t:s0 ... .bash_profile
drwx------. 2 postgres postgres system_u:object_r:postgresql_db_t:s0 ... data
----
If the installation program missed something, fix it executing
If the installation program missed something, fix it executing
[source,]
----
[…]# restorecon -vFr /var/lib/pgsql
[…]# ls -alZ /var/lib/pgsql/
----
It is also a prerequisite that exclusively the user postgres has access to the directory pgsql and its subdirectories. Usually the installer takes care of it. Fix it if necessary.
It is also a prerequisite that exclusively the user postgres has access to the directory pgsql and its subdirectories. Usually the installer takes care of it. Fix it if necessary.
[source,]
----
[…]# chown -R postgres:postgres /var/lib/pgsql
@ -141,6 +140,21 @@ In case of connection issues there is most probably a SELinux configuration miss
For admin access Fedora postgresql is configured to obtain the host's operating system user name from the kernel and using it as the allowed database user name. Therefore, as soon as someone can authentiate on the host as user __postgres__, that person has administrative privileges on the postgresql server without any additional password prompt. The only one who can do that by default, is root. Root can configure additional users to be able to su to postgres. In any case, in a whatever emergency, if any then the system administrator is able to quickly access postgresql server unhindered and salvage what can still get salvaged.
This capability is configured in the ~/data/pg_hba file, together with other properties.
[source,]
----
[…]# vim /var/lib/pgsql/data/pg_hba.conf
...
# PostgreSQL Client Authentication Configuration File
# ===================================================
...
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
----
It is really not a good idea to change the entry in the line local all ... in any way. Whatever you configure later in this file, do not change this line, or only do so if you are absolutely sure of what you are doing.
If local regulations make it necessary to replace these procedures with a dedicated authentication by postgresql itself, one of the other procedures can be configured later. In general, however, it is not advisable to make any changes. Once root is compromised, there are a lot of completely different problems to get tackled.
==== Client user access
@ -153,9 +167,12 @@ The configuration is done in the file `pg_hba.conf` in the `data` subdirectory.
[…]# vim /var/lib/pgsql/data/pg_hba.conf
# PostgreSQL Client Authentication Configuration File
# ===================================================
...
...
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
...
...
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv4 internal network connections: # <- modification!
@ -237,55 +254,6 @@ If everything works as expected, enable autostart of postgresql,
[…]# systemctl enable postgresql
----
== 4. A system administrator's quick PostgreSQL cheat sheet
Get access to a postgresql database and get a postgres terminal prompt::
+
----
[...]# sudo -i -u postgres psql
psql (16.3)
Type "help" for help.
postgres=#
----
List all databases::
+
----
postgres=# \l
----
Connect to a database::
+
----
postgres=# \c <database_name_from_above_list>
----
List all tables in the database connected to::
+
----
postgres=# \dt
----
List all users / roles::
+
----
postgres=# \du
----
Create a new user / role::
+
----
postgres=# CREATE USER new_user_name WITH PASSWORD 'password';
----
Change password of a user / role::
+
----
postgres=# ALTER USER user_name WITH PASSWORD 'new_password';
----
Enjoy a powerful DBMS.