<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Piotr Bracha on Medium]]></title>
        <description><![CDATA[Stories by Piotr Bracha on Medium]]></description>
        <link>https://medium.com/@pbracha?source=rss-4f07f6d9363a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KWyYDB2QEiREiB-tQXRD5w.jpeg</url>
            <title>Stories by Piotr Bracha on Medium</title>
            <link>https://medium.com/@pbracha?source=rss-4f07f6d9363a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:28:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pbracha/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Configuring permissions for specific users for the tmp/ directory of a Ruby on Rails application]]></title>
            <link>https://pbracha.medium.com/configuring-permissions-for-specific-users-for-the-tmp-directory-of-a-ruby-on-rails-application-5e0b4b96e33f?source=rss-4f07f6d9363a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e0b4b96e33f</guid>
            <category><![CDATA[app-permissions]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[user-privileges]]></category>
            <dc:creator><![CDATA[Piotr Bracha]]></dc:creator>
            <pubDate>Wed, 25 Mar 2026 22:31:00 GMT</pubDate>
            <atom:updated>2026-03-25T22:31:00.663Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1G8LC9Q_xhB6jomlt3do4A.png" /></figure><p>Recently at work, I was tasked with granting Postgres and Passenger users read and write access to the “tmp” directory located in the root directory of a Ruby on Rails application. The task seemed straightforward, but one problem arose that prolonged the time it took to complete it.</p><ol><li>On the <strong>root</strong> user’s account:</li></ol><pre>groupadd audio_drop_rw<br>usermod -aG audio_drop_rw passenger<br>usermod -aG audio_drop_rw postgres<br>systemctl restart postgresql@14-main   # &lt;-- very important to do this #</pre><p>2. On the <strong>passenger</strong> user’s account:</p><pre>setfacl -b /home/passenger/audio_drop/tmp<br>setfacl -k /home/passenger/audio_drop/tmp<br><br>chown passenger:passenger /home/passenger/audio_drop/tmp<br>chmod 2750 /home/passenger/audio_drop/tmp<br><br>setfacl -m g:audio_drop_rw:rwx /home/passenger/audio_drop/tmp<br>setfacl -d -m g::r-x /home/passenger/audio_drop/tmp<br>setfacl -d -m g:audio_drop_rw:rwx /home/passenger/audio_drop/tmp<br>setfacl -d -m m:rwx /home/passenger/audio_drop/tmp</pre><p>The above commands enabled the following:<br>- Works from the shell<br>- Manual creation between Postgres and Passenger works<br>- Also works correctly from Rails</p><p>However, when accessed from within the application, a “permission denied” error occurred. I will cover it later.</p><p>3. If there are any files in the tmp/audio-dump directory, it is required to perform the following steps as the root user:</p><pre>find /home/passenger/audio_drop/tmp/audio-dump -type d -exec setfacl -m g:audio_drop_rw:rwx {} \;<br>find /home/passenger/audio_drop/tmp/audio-dump -type d -exec setfacl -m m:rwx {} \;<br>find /home/passenger/audio_drop/tmp/audio-dump -type d -exec setfacl -d -m g::r-x {} \;<br>find /home/passenger/audio_drop/tmp/audio-dump -type d -exec setfacl -d -m g:audio_drop_rw:rwx {} \;<br>find /home/passenger/audio_drop/tmp/audio-dump -type d -exec setfacl -d -m m:rwx {} \;<br>find /home/passenger/audio_drop/tmp/audio-dump -type f -exec setfacl -m g:audio_drop_rw:rw {} \;<br>find /home/passenger/audio_drop/tmp/audio-dump -type f -exec setfacl -m m:rw {} \;</pre><p>4. Ok, let’s find out why we had “permission denied” error although ACLs are set. To do this we need to execute (in this case PostgreSQL 14 is used):</p><pre>ps -u postgres -o pid,cmd | grep &#39;/usr/lib/postgresql/14/bin/postgres&#39; | awk &#39;{print $1}&#39;</pre><p>5. The command above will return a PID, which you must enter in the following command:</p><pre>grep &#39;^Groups:&#39; /proc/&lt;PID&gt;/status</pre><p>Output will be similar to the following (of course IDs can be different in your system):</p><pre>Groups: 115 116 1013</pre><p>The group IDs will be returned for groups whose names can be easily identified by specifying the ID as a parameter to the grep command, e.g., grep 115 /etc/group. <strong>In my case ID = 1013 is related with group created at the beginning and, as you can see, it is visible to the postgresql server, because in the 1st point of this tutorial I performed postgresql cluster restart. </strong>As a result, the PostgreSQL cluster can see the new group and has the necessary permissions to modify the contents of the directories within “tmp”. Now Rails application started working properly without “permission denied” error.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e0b4b96e33f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating certificates using Lets Encrypt]]></title>
            <link>https://pbracha.medium.com/creating-certificates-using-lets-encrypt-dcaf5c29c4c9?source=rss-4f07f6d9363a------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcaf5c29c4c9</guid>
            <category><![CDATA[certbot]]></category>
            <category><![CDATA[renewal]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <category><![CDATA[lets-encrypt]]></category>
            <dc:creator><![CDATA[Piotr Bracha]]></dc:creator>
            <pubDate>Fri, 27 Feb 2026 17:06:01 GMT</pubDate>
            <atom:updated>2026-02-27T17:06:01.034Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tj3H1UuEzrf8hZJJaVLvOw.png" /></figure><ol><li>Generating SSL certificates requires the installation of the <strong>certbot</strong> client. To do this, perform the following steps:</li></ol><ul><li>apt remove certbot — if it was previously installed using apt</li><li>snap install --classic certbot</li><li>ln -s /snap/bin/certbot /usr/bin/certbot</li></ul><p>2. Assuming that we have a vhost prepared for a given domain (even the simplest one with listen 80 and server_name for example shop domain with and without www), all we need to do is run the command certbot --nginx -d example.com -d <a href="http://www.example.com/">www.example.com</a>. During the process, only the first time after installation, enter the email address to which all notifications will be sent. You will then be asked to agree to the terms and conditions. After a few moments, the process should be complete, and the domain will be visible in the browser via https.</p><p>3. If you do not have an nginx/apache web server, you can still generate a certificate. Just run the command certbot certonly --standalone --preferred-challenges http -d example.com.</p><p>4. If, for example, we have a node server running from a local user account, certificates generated from the root account will not be available for use. For this purpose, I recommend using the script I wrote to solve this problem (pm2 is used to run node server):</p><pre>#!/bin/bash<br><br>#deploy this script inside /etc/letsencrypt/renewal-hooks/deploy<br><br>domain=&quot;example.com&quot;<br>node_cert_dir=&quot;/home/user/example_dir/ssl&quot;<br>node_user=&quot;example_user&quot;<br><br>cp /etc/letsencrypt/live/$domain/{fullchain,privkey}.pem $node_cert_dir<br>cd $node_cert_dir<br>chown $node_user&quot;:&quot;$node_user $node_cert_dir/*.pem<br><br># after certs deployment restart an application<br>su - deploy -c &#39;/home/deploy/.nvm/versions/node/v14.15.4/bin/node /home/deploy/.nvm/versions/node/v14.15.4/bin/pm2 restart server&#39;</pre><p>The above script will also be useful after automatic certificate renewal by certbot. It will allow you to copy them to the appropriate path and assign the appropriate permissions. To do this, it is best to place it in the <strong>/etc/letsencrypt/renewal-hooks/deploy</strong> path immediately after the first certificate generation, and it will take care of the automation. ;)</p><p>If you run into certificate renewal issues, it’s worth starting with basic troubleshooting by running certbot renew --cert-name example.com --dry-run -v, where --cert-name points to the certificate name (often covering both the www and non-www versions of the domain) and -v is a flag which can be used multiple times to incrementally increase the verbosity of output. There are also additional switches (based on the <a href="https://eff-certbot.readthedocs.io/en/stable/using.html">docs</a>):</p><pre>--debug               Show tracebacks in case of errors (default: False)<br>--debug-challenges    After setting up challenges, wait for user input<br>                        before submitting to CA. When used in combination with<br>                        the `-v` option, the challenge URLs or FQDNs and their<br>                        expected return values are shown. (default: False)</pre><p>and of course logs directory /var/log/letsencrypt.</p><p>You can also verify the certificate’s validity period with openssl x509 -in /etc/letsencrypt/live/example.com/cert.pem -text -noout | grep -A2 Validity. If the problem is specifically related to the renewal process timing — especially on servers that manage a large number of certificates — one practical fix is to add nginx-sleep-seconds = 30 to /etc/letsencrypt/cli.ini. This value (in seconds) gives Nginx extra time to apply configuration changes and reload before Let’s Encrypt attempts to connect back for validation; the default is 1 second.</p><p>If necessary, you can manually check the expiration dates of certificates by executing the certbot certificates command and entering the value from the “Certificate Name:” line as a parameter for the certbot rene --cert-name &lt;certificate-name&gt; command.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcaf5c29c4c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DigitalOcean Spaces — creating and configuring a connection]]></title>
            <link>https://pbracha.medium.com/digitalocean-spaces-creating-and-configuring-a-connection-0afd1d919b4f?source=rss-4f07f6d9363a------2</link>
            <guid isPermaLink="false">https://medium.com/p/0afd1d919b4f</guid>
            <category><![CDATA[digitalocean-spaces]]></category>
            <category><![CDATA[s3fs]]></category>
            <dc:creator><![CDATA[Piotr Bracha]]></dc:creator>
            <pubDate>Wed, 25 Feb 2026 19:11:01 GMT</pubDate>
            <atom:updated>2026-02-25T19:11:01.148Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_iCMeA6LqjyHnlgOqIRoxQ.png" /></figure><p>In this guide, I will describe step by step how to create a Space on DigitalOcean and then connect to it from the server.</p><ol><li>Log in to <a href="https://cloud.digitalocean.com/">the customer panel</a>.</li><li>Click the green <strong>Create</strong> button in the upper right corner of the page.</li><li>Choose Spaces Object Storage.</li><li>In the open view, we indicate the following in sequence:</li></ol><ul><li>“Choose a datacenter region” — the best transfers are achieved when Space is in the same data center as the server</li><li>“Choose a Storage type” — “Standard storage” is for data which are often read / write or must be served fast for users / applications, i.e. static assets, audio / video, application data that is read regularly. “Cold storage” is for data that is stored for a long time, rarely accessed, where low storage costs are important, and you accept limitations, i.e. logs, backups.</li><li>“Content Delivery Network” — choose to enable or not</li><li>“Choose a unique Spaces Bucket name” — self-explanatory ;-)</li><li>“Selecta project” — choose a project where to create specific Spaces Object Storage</li></ul><p>5. Click the <strong>Create a Spaces Bucket</strong> button. After a few seconds, a view will open where you can upload files, create new directories, and access settings in the<strong> Settings tab</strong>.</p><p>6. Click on the <strong>Settings tab</strong> and copy the endpoint name, e.g., to a notepad.</p><p>7. Then scroll down a little until you find “Create Access Key” button. Click it.</p><p>8. A new window will appear where you can select the scope of permissions, select the resource to which specific permissions will be granted, and finally name the key. When you will be ready click “Create Access Key” button.</p><p>9. In the table you will see newly created key and its access id. Importantly, the Secret key will no longer be visible after you leave this tab, so also copy it. With a complete set of keys and the endpoint address, we can move on to the next part, which is installing and configuring the s3 client that we will use to connect to our Space.</p><p>10. Log into the server console and enter the commands apt update and apt install s3fs in sequence. Participation in the installation ends with expressing our willingness to install the program by pressing “<strong>y”</strong> and confirming with enter.</p><p>11. In the home directory, create a file named <strong>.passwd-s3fs</strong> and assign read and write permissions to the file owner using the command chmod 600. Place the previously generated keys in it using the command echo generated_token:generated_secret &gt; ~/.passwd-s3fs.</p><p>12. Edit the <strong>/etc/fuse.conf</strong> file and uncomment the user_allow_other line, which will allow Space to be used not only as root (by default, Space is mounted only for root). Exit the file and save the changes. Requires using -o allow_other in the command below.</p><p>13. Enter the id command to obtain two identifiers that will be needed later: <strong>uid</strong> (user id) and <strong>gid</strong> (group id).</p><p>14. Create a folder to which Space (or a subfolder of Space) will later be mounted.</p><p>15. Mount Space to the folder created above using the command:</p><pre>s3fs space_name:/subdirectory_name_in_space /dir_on_server -o passwd_file=${HOME}/.passwd-s3fs -o url=https://copied_endpoint_address -o use_cache=/tmp -o allow_other -o use_path_request_style -o uid=user_id -o gid=group_id</pre><p>If you want to mount the entire Space to a directory on the server, simply delete “:<strong>/subdirectory_name_in_space”</strong> from the above command.</p><p>Some options explanation:</p><ul><li>-o use_path_request_style required by S3-compatible services like Spaces. It forces path-style addressing like https://endpoint/bucket/key rather than <a href="https://bucket.endpoint/key.">https://bucket.endpoint/key.</a></li><li>-o uid=user_id and -o gid=group_id — set owner uid/gid for files</li><li>-o use_cache=/tmp — enable and points to local cache dir used by s3fs, which stores data during read/write process</li></ul><p>16. The mount point has 777 permissions by default and is owned by the user and group whose uid and gid we specified above in the command.</p><p>17. In my case, I wanted to save files in Space from within an application running in a Docker container. <strong>Ultimately, it turned out that all I had to do was restart the Docker service, and the uploaded files became visible</strong> in the DigitalOcean repository.</p><p>Unmounting is performed using the command fusermount -uz dir_on_server. It provides logical unmount and in reality only when it is no longer in use. You can also use lsof +D dir_on_server and fuser -m dir_on_serverto check who is blocking the process, andps aux | grep folder_on_server to display the mapping and kill the process by entering kill -9 pid (it has happened that unmounting did not terminate the process, so in that case you need to kill it).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0afd1d919b4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Resetting the VMware ESXi administrator password]]></title>
            <link>https://pbracha.medium.com/resetting-the-vmware-esxi-administrator-password-362c11d7321d?source=rss-4f07f6d9363a------2</link>
            <guid isPermaLink="false">https://medium.com/p/362c11d7321d</guid>
            <category><![CDATA[vmware-esxi]]></category>
            <category><![CDATA[password-recovery]]></category>
            <category><![CDATA[password-reset]]></category>
            <dc:creator><![CDATA[Piotr Bracha]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 22:46:00 GMT</pubDate>
            <atom:updated>2026-02-17T22:46:00.741Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*54JqEMxo5cVNY0LD7kgqcw.png" /></figure><p>This is the old case from far past (around late 2021). ;-)</p><p>To even begin resetting your password, you need to prepare a bootable USB drive with Ubuntu Desktop. At the time of writing this guide, the latest version is 20.10, but if you plan to install it somewhere later, it is better to choose a version with long-term support, i.e., 20.04.1 LTS. After downloading the image, install it on a USB drive using Rufus.</p><ol><li>Boot the machine from the USB drive created above and select the <strong>Try Ubuntu</strong> option.</li><li>After launching the desktop, type <strong>gparted </strong>in the application search engine, and then run the program.</li><li>The program displays the current list of partitions. Two of them will be approximately 250MB in size. In my case, these were <strong>/dev/sda5</strong> and <strong>/dev/sda6</strong>, and the hypervisor / system image is on the first one.</li><li>Launch the terminal and execute a series of commands that can be used by copying and pasting:</li></ol><pre>sudo -s<br>mount /dev/sda5 /mnt<br>cd /mnt<br>ls<br>cp state.tgz /tmp<br>cd /tmp<br>tar xzf state.tgz<br>ls<br>tar xzf local.tgz<br>ls<br>cd etc<br>nano shadow<br>----&gt;&gt;At this point, the shadow file is open for editing. Delete the hash between the first and second colons. Exit the file and save the changes.<br>cd ..<br>tar czf local.tgz etc<br>tar czf state.tgz local.tgz<br>cp state.tgz /mnt/<br>umount /mnt<br>reboot<br>----&gt;&gt;Remove the USB flash drive and wait for ESXi to start up.</pre><h3>Disclaimer</h3><ol><li>Reset performed on VMware ESXi version 6.7.0.</li><li>In my case, after deleting the password, I still could not log in to the console from the hypervisor machine, despite entering my username and leaving the password field blank.</li><li>I managed to log in to the hypervisor panel from the browser and set a secure password. After logging in to the panel and rebooting the machine, the set password also started working in the console.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=362c11d7321d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating your own services for Linux]]></title>
            <link>https://pbracha.medium.com/creating-your-own-services-for-linux-533db1752fb7?source=rss-4f07f6d9363a------2</link>
            <guid isPermaLink="false">https://medium.com/p/533db1752fb7</guid>
            <category><![CDATA[linux-service]]></category>
            <category><![CDATA[ubuntu-service]]></category>
            <dc:creator><![CDATA[Piotr Bracha]]></dc:creator>
            <pubDate>Sat, 14 Feb 2026 20:26:00 GMT</pubDate>
            <atom:updated>2026-02-14T20:26:00.753Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zGBgVyQMUAOxLxXwr7cFXw.png" /></figure><p>In systems that can run services via systemd (e.g., Ubuntu 16.04+), you can configure a service run by a local user as follows:</p><ol><li>We log in to a given local user directly on the server or via SSH. <strong>It is not possible</strong> to switch to a local user from the root account using su — local_user, because an error will occur when starting such a service due to the lack of a correctly configured systemd / user bus user session for systemctl --user.</li><li>The path where we create new services is as follows: <strong>/home/local_user/.config/systemd/user</strong>. Inside, we create files named according to the pattern <strong>service_name.service</strong>.</li><li>On the second console, log in to the root user account to execute the following one-time command: loginctl enable-linger local_user. This command allows the <strong>local_user</strong> user to run services that are intended to run long-term and will continue to run even if the user logs out of the console.</li><li>Return to the console with the local user logged in and start the service with the command: systemctl --user start service_name.service.</li><li>Next, enable the service to start at system startup by executing systemctl --user enable service_name.service.</li><li>We can verify the operation of the service by entering systemctl --user status service_name.service.</li></ol><p>For services that are to be run with root privileges:</p><ol><li>Create services in <strong>/etc/systemd/system/</strong>.</li><li>Start a given service with the command: systemctl start service_name.service.</li><li>Then, we enable the service to start at system startup by executing systemctl enable service_name.service.</li><li>We can verify the operation of the service by entering systemctl status service_name.service.</li><li>To check how many resources it consumes: systemd-cgtop -m.</li></ol><p>Example local user’s service:</p><pre>[Unit]<br>Description=Sidekiq-rails-app<br>After=network.target<br><br>[Service]<br>Type=simple<br>WorkingDirectory=/home/passenger/rails-app<br>ExecStart=/bin/bash -lc &#39;bundle exec sidekiq -L log/sidekiq.log -e production -P tmp/sidekiq.pid&#39;<br>Restart=on-failure<br>RestartSec=3<br><br>[Install]<br>WantedBy=default.target</pre><p>If the service, e.g. Postgresql, uses a connected external volume, change the line After=network.target — based on the above example — to this:</p><pre>After=network-online.target<br>Wants=network-online.target<br>RequiresMountsFor=/mnt/path/to/volume</pre><p>This ensures the service starts only after the mount is available (more reliable than relying on the network target alone). On the other hand, if the service is created from the root level rather than a local user, last line of the above example service code will look like this:</p><pre>WantedBy=multi-user.target</pre><p>Multi-user is a target corresponding to runlevel 3 in older Linux versions, and it is responsible for starting the machine without a graphical interface, with network support.</p><h3><strong>BONUS</strong></h3><p>If Monit does not want to monit specific service deployed by local user (in my case it was of course related with sidekiq service) account on Ubuntu Server 24.04 LTS but the same code works on Ubuntu 22.04 LTS you need to:</p><ol><li>Verify specific properties of the Monit service:</li></ol><pre>systemctl show monit -p ProtectHome -p ReadWritePaths -p ReadOnlyPaths</pre><p>2. If you have ProtectHome=yes then you need to modify your Monit service by executing command systemctl edit monit and between two comments at the begginging of the file paste this:</p><pre>[Service]<br>ProtectHome=read-only</pre><p>3. Then execute:</p><pre>systemctl daemon-reload<br>systemctl restart monit</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=533db1752fb7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Problems during Phpmyadmin installation]]></title>
            <link>https://pbracha.medium.com/problems-during-phpmyadmin-installation-743bdb278b49?source=rss-4f07f6d9363a------2</link>
            <guid isPermaLink="false">https://medium.com/p/743bdb278b49</guid>
            <category><![CDATA[phpmyadmin-ubuntu]]></category>
            <dc:creator><![CDATA[Piotr Bracha]]></dc:creator>
            <pubDate>Fri, 13 Feb 2026 20:26:00 GMT</pubDate>
            <atom:updated>2026-02-13T20:26:00.975Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hUGPafwSn6atzdl7xclalQ.png" /></figure><p>I encountered several problems during the installation of Phpmyadmin. Below are their descriptions and solutions.</p><ol><li>During installation, an error pops up indicating that the application password does not meet the requirements set by the MySQL configuration. Regardless of the measures taken to reduce the level of protection, the effect cannot be achieved. This is a bug that only affects Phpmyadmin. The only thing you can do is run the UNINSTALL COMPONENT &quot;file://component_validate_password&quot;; command from MySQL, install Phpmyadmin, and then enable the password validation module INSTALL COMPONENT &quot;file://component_validate_password&quot;;. You can verify that the component is enabled with the command show variables like &#39;validate_password%&#39;;.</li><li>Another problem was the HTTP 403 code when opening Phpmyadmin in the browser. To solve this problem, edit the <strong>/etc/nginx/sites-enabled/default</strong> file responsible for the default page opened by the Nginx server. In this file:</li></ol><ul><li>add index.php to the index line and delete <strong>index.nginx-debian.html</strong></li><li>uncomment the lines:</li></ul><pre>location ~ \.php$ {<br><br>    include snippets/fastcgi-php.conf;<br><br>    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;<br><br>}</pre><p>3. For greater security, it is worth changing:</p><ul><li>the default directory path from <strong>/var/www/html</strong> to <strong>/var/www</strong> by editing the root line in the <strong>/etc/nginx/sites-enabled/default</strong> file.</li><li>rename the symbolic link from <strong>phpmyadmin</strong> to, for example, <strong>secure_auth</strong> — ln -s /usr/share/phpmyadmin /var/www/secure_auth</li></ul><p>4. The Phpmyadmin documentation states that the current version (5.1.0 at the time of writing) requires PHP 7.1 or higher. I verified this. First, I had to run the command ALTER USER &#39;root&#39;@&#39;localhost&#39; IDENTIFIED WITH caching_sha2_password BY &#39;password&#39;; in mysql (ver. 8.0.23), which allowed <strong>root</strong> to be authenticated with a password instead of a socket. Second, I had to install at least PHP 7.4 (tested on 7.4.3 and 8.0.3).</p><p>5. After updating Phpmyadmin, edit the file <strong>/usr/share/phpmyadmin/libraries/vendor_config.php </strong>and change two lines inside:</p><ul><li>define(&#39;TEMP_DIR&#39;, ROOT_PATH . &#39;tmp&#39; . DIRECTORY_SEPARATOR); to define(&#39;TEMP_DIR&#39;, &#39;/var/lib/phpmyadmin/tmp/&#39;);</li><li>define(&#39;CONFIG_DIR&#39;, ROOT_PATH); to define(&#39;CONFIG_DIR&#39;, &#39;/etc/phpmyadmin/&#39;);</li></ul><p>Thanks to these two changes, we will get rid of the errors visible at the bottom of the Phpmyadmin panel immediately after logging in:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*3oR13zlRwgySCipmmviIHA.png" /></figure><p>All problems appeared on the Ubuntu 22.04 LTS with PhpMyadmin 4.9.3 and 5.1.0, MySQL 8.0.23, PHP 7.4.3 and 8.0.3.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=743bdb278b49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Drop database despite active connections — Postgresql]]></title>
            <link>https://pbracha.medium.com/drop-database-despite-active-connections-postgresql-a65083ceb2cb?source=rss-4f07f6d9363a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a65083ceb2cb</guid>
            <category><![CDATA[postgresql-tutorials]]></category>
            <category><![CDATA[postgresql-database]]></category>
            <category><![CDATA[database-administration]]></category>
            <dc:creator><![CDATA[Piotr Bracha]]></dc:creator>
            <pubDate>Sun, 08 Feb 2026 17:46:00 GMT</pubDate>
            <atom:updated>2026-02-08T17:46:00.701Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PufDC4qM3nkbxcmmgs4Pfw.png" /></figure><h3>Drop database despite active connections — Postgresql</h3><p>Sometimes, the database on which you want to perform a drop database has active sessions that prevent this action from being performed. To do this, you need to (postgres below ver.13):</p><ol><li>Log in as the <strong>postgres</strong> user and run psql.</li><li>List the databases using\l.</li><li>Check database you are connected in and what is version of the server:</li></ol><pre>SELECT current_database(), current_user;<br>SHOW server_version;</pre><p>4. <strong>For PostgreSQL &lt; 13</strong> <br>Block new connections to the target database:</p><pre>ALTER DATABASE database_name WITH ALLOW_CONNECTIONS false;</pre><p>5. Check active sessions for the target database:</p><pre>SELECT * FROM pg_stat_activity WHERE datname = &#39;database_name&#39;;</pre><p>6. Terminate active sessions (“AND” condition used for additional safety to not kill own session):</p><pre>SELECT pg_terminate_backend (pid) FROM pg_stat_activity WHERE datname = &#39;database_name&#39; AND pid &lt;&gt; pg_backend_pid();</pre><p>6. Drop the database:</p><pre>DROP DATABASE database_name;</pre><p>7. If the drop failed (or you were doing maintenance and want to re-open access), allow connections again:</p><pre>ALTER DATABASE database_name WITH ALLOW_CONNECTIONS true;</pre><p><strong>For PostgreSQL ≥ 13 <br></strong>First three steps are similar. Then you need to:</p><ol><li>(Optional but recommended) Block new connections:</li></ol><pre>ALTER DATABASE nazwa_bazy WITH ALLOW_CONNECTIONS false;</pre><p>2. Drop the database and force-terminate existing sessions:</p><pre>DROP DATABASE IF EXISTS database_name WITH (FORCE);</pre><p>3. If the drop failed (or for maintenance), allow connections again:</p><pre>ALTER DATABASE nazwa_bazy WITH ALLOW_CONNECTIONS true;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a65083ceb2cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Increasing space on an LVM logical partition on Linux]]></title>
            <link>https://pbracha.medium.com/increasing-space-on-an-lvm-logical-partition-on-linux-75bfe57375e8?source=rss-4f07f6d9363a------2</link>
            <guid isPermaLink="false">https://medium.com/p/75bfe57375e8</guid>
            <category><![CDATA[lvm]]></category>
            <category><![CDATA[volume-resize]]></category>
            <category><![CDATA[logical-volume-management]]></category>
            <dc:creator><![CDATA[Piotr Bracha]]></dc:creator>
            <pubDate>Thu, 05 Feb 2026 17:46:01 GMT</pubDate>
            <atom:updated>2026-02-05T17:46:01.043Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ssa1V9yQwSSCoWIFr6J3ng.png" /></figure><ol><li>Verify the number of sectors for the partitions present in the system using the fdisk -l command to determine the value of the last sector on the last partition (the next newly created partition will start from the next sector). This value is shown in the END column.</li><li>Creating a new partition is initiated by the command fdisk /dev/vda (in this case, the physical disk is labeled vda). Then, enter the appropriate letter and confirm your selection with Enter (unless otherwise specified, just press Enter):</li></ol><ul><li><strong>n</strong> — launches the new partition creation wizard</li><li><strong>p</strong> — specifies the partition type, in this case primary</li><li>enter a value one greater than the highest value read in the previous step</li><li><strong>t</strong> — enter the hexadecimal code for the partition type — we are interested in Linux LVM — enter <strong>8e</strong></li><li><strong>w</strong> — save the changes</li></ul><p>3. Use the partition created above with LVM using the command pvcreate /dev/vda3 (this is the name given to the partition automatically).</p><p>4. Add a physical volume (Physica Volume — verified with the pvs command) to an existing volume group (Volume Group — verified with the vgs command) using the vgextend testing-vg /dev/vda3 command (<strong>testing-vg</strong> is the name of the group).</p><p>5. Verify the free space in the Volume Group using the vgdisplay command. We are interested in the <strong>Free PE</strong> line.</p><p>6. Extend the logical volume with the free space verified above (in this case, 7681) using the command lvextend -l +7681 /dev/testing-vg/root (path to be obtained from the result of the lvdisplay command).</p><p>7. Resize the file system used inside the logical volume resize2fs /dev/testing-vg/root .</p><p>8. Verify the size of the logical partition in the <strong>LV Size</strong> line using the lvdisplay command. Verify the available <strong>Free PE</strong>, which should be equal to 0. The number can be obtained by entering vgdisplay.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75bfe57375e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring OpenVPN on EdgeRouter — my updates to original tutorial and some solutions related…]]></title>
            <link>https://pbracha.medium.com/configuring-openvpn-on-edgerouter-my-updates-to-original-tutorial-and-some-solutions-related-a956f5efed87?source=rss-4f07f6d9363a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a956f5efed87</guid>
            <category><![CDATA[certificate]]></category>
            <category><![CDATA[edgerouter]]></category>
            <category><![CDATA[openvpn-setup]]></category>
            <category><![CDATA[problem-solving]]></category>
            <dc:creator><![CDATA[Piotr Bracha]]></dc:creator>
            <pubDate>Thu, 05 Feb 2026 13:32:33 GMT</pubDate>
            <atom:updated>2026-02-05T13:32:33.149Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-1ZSXuZzxmAsqZ68C2qHzQ.png" /></figure><h3>Configuring OpenVPN on EdgeRouter — my updates to original tutorial and some solutions related with certificates</h3><p>I used this <a href="https://help.ui.com/hc/en-us/articles/115015971688-EdgeRouter-OpenVPN-Server">original tutorial</a> but during deployment I made some improvements/updates. Here they are:</p><ol><li>I did not carry out the last instruction from point 19 and the instruction from point 21.</li><li>On the client side, I had to explicitly specify the AES-256-GCM cipher algorithm in the .ovpn file using cipher AES-256-GCM.</li><li>The network address for use by OpenVPN clients in point 19 is 10.100.0.0/24 → set interfaces openvpn vtun0 server subnet 10.100.0.0/24.</li><li>I also had to restart the vtun0 interface by performing the following steps in sequence:</li></ol><pre>configure<br><br>set interfaces openvpn vtun0 disable<br><br>commit<br><br>delete interfaces openvpn vtun0 disable<br><br>commit</pre><p>5. In configure mode configure I added explicitly set interfaces openvpn vtun0 openvpn-option &quot;--cipher AES-256-GCM&quot;.</p><p>6. For debugging purposes, I used level 7 (default mode 3) set interfaces openvpn vtun0 openvpn-option &quot;--verb 7&quot;.</p><p>7. If all traffic need to be redirected (in other words, whole traffic to the Internet will be pushed through the VPN tunnel), add redirect-gateway def1 to the configuration (.ovpn) file on the client.</p><p>I did not find on the Internet a way to renew specific openvpn client certificate on the EdgeRouter. I have tried on my own and I found the solution. In the following example, I am renewing my certificate. Each person has own one.</p><ol><li>Checking certificate validity:</li></ol><pre>openssl x509 -noout -text -in pbracha.pem | grep -i -A2 validity</pre><p>2. Exporting “CSR” from the expiring certificate to the <strong>newreq.pem</strong> file. Executed on the router in the <strong>/config/auth/</strong> path:</p><pre>openssl x509 -x509toreq -in pbracha.pem -signkey pbracha.key -out newreq.pem</pre><p>3. Moving the <strong>newreq.pem</strong> file to the <strong>/usr/lib/ssl/misc/</strong> directory:</p><pre>mv newreq.pem /usr/lib/ssl/misc/</pre><p>4. Copy <strong>pbracha.key</strong> with the required name and place it in the target directory:</p><pre>cp /config/auth/pbracha.key /usr/lib/ssl/misc/newkey.pem</pre><p>5. <strong>[Optional — if you cannot sign the certificate in the next step]</strong> Go to the <br><strong>/usr/lib/ssl/misc/</strong> directory and revoke the current certificate:</p><pre>cd /usr/lib/ssl/misc/<br>./CA.pl -revoke /config/auth/pbracha.pem</pre><p>6. Go to the <strong>/usr/lib/ssl/misc/</strong> directory, change the owner of the <strong>newreq.pem</strong> file to <strong>root:root</strong>, and start signing:</p><pre>cd /usr/lib/ssl/misc/<br>chown root:root newreq.pem<br>./CA.pl -sign</pre><p>7. Moving generated files to the <strong>/config/auth/</strong> path:</p><pre>mv newcert.pem /config/auth/pbracha.pem<br>mv newkey.pem /config/auth/pbracha.key</pre><p>8. Copy the <strong>pbracha.pem</strong> and <strong>pbracha.key</strong> files to the client.</p><p>I found information on how and which files to edit on the router so that new certificates have a longer validity period — available <a href="https://community.ui.com/questions/OpenVPN-on-Edge-Router-How-to-renew-an-expired-CA/42496335-878f-4602-8593-63aa2213c967">at the link</a>, but in case it stops working, I am also posting a screenshot of the answer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UdBrpuL5C-MeG8lR_14X-A.png" /></figure><p>I wanted to sign a new certificate with the same CA as the current valid certificate. I used the CA.pl tool (a Perl script) available on the router. Unfortunately, an error was returned along with the serial number of the current certificate, which prevented the new certificate from being signed. On impulse, I deleted the existing certificate without revoking it first. This is where the problem arose. Fortunately, even without the physical certificate file, it can be revoked. Openssl on EdgeRouter keeps all copies of signed certificates in the path <strong>/usr/lib/ssl/misc/demoCA/newcerts/</strong>. We can obtain serial from the file <strong>/usr/lib/ssl/misc/demoCA/index.txt</strong>. For example for CN=pbracha — output — proper serial is in 4th column:</p><pre>grep -F &quot;/CN=pbracha&quot; /usr/lib/ssl/misc/demoCA/index.txt | cut -f4</pre><p>If we would have a few lines for the same CN (for example old and new ones) we are able to show all of them with status and date:</p><pre>grep -F &quot;/CN=pbracha&quot; /usr/lib/ssl/misc/demoCA/index.txt | awk -F&#39;\t&#39; &#39;{print &quot;STATUS=&quot;$1, &quot;EXP=&quot;$2, &quot;SERIAL=&quot;$4, &quot;SUBJ=&quot;$6}&#39;</pre><p>With the serial number, we can use it for the following command:</p><pre>openssl ca -revoke /usr/lib/ssl/misc/demoCA/newcerts/<strong>HERE_PUT_OBTAINED_SERIAL</strong>.pem -keyfile /config/auth/cakey.pem -cert /config/auth/cacert.pem</pre><p>If, after upgrading the system, the <strong>/usr/lib/ssl/misc/demoCA</strong> directory has been deleted from the router, a copy of it can be found in the path <br><strong>/root.dev/w.o/usr/lib/ssl/misc</strong>. Simply copy it and the problem with signing certificates should be solved. <strong>The expiration dates of the certificates are also replaced.</strong></p><p>Procedure for renewing the cacert.pem file (this method will work for any certificate that has not yet expired):</p><ol><li>I generated a new <strong>cacert_new.pem</strong> certificate signed with the <strong>existing</strong> <strong>cakey.pem</strong> key, which was created together with the cacert.pem file:</li></ol><pre>cd /usr/lib/ssl/misc<br>openssl x509 -in /config/auth/cacert.pem \<br>  -signkey /config/auth/cakey.pem \<br>  -days 3650 -sha256 \<br>  -set_serial 0x$(openssl rand -hex 16) \<br>  -out cacert_new.pem</pre><p>2. I verified that one of the already issued certificates is correctly validated by the <strong>cacert_new.pem</strong> certificate:</p><pre>openssl verify -CAfile cacert_new.pem /config/auth/pbracha.pem</pre><p>3. Result of the above command:</p><pre>/config/auth/pbracha.pem: OK</pre><p>4. All that remains is to send to all users a new file → cacert_new.pem (first rename it to cacert.pem so that users do not have to change anything on their devices). Also move it to <strong>/config/auth</strong> on the router and make a copy the existing cacert.pem.</p><p>If the error Use of uninitialized value $1 in concatenation (.) or string at ./CA.pl line 133 appears when running the CA.pl script, a correction must be made in the CA.pl script:</p><ol><li>Edit this file using vi editor:</li></ol><pre>vi CA.pl</pre><p>2. Find line 133:</p><pre>$RET = run(&quot;$REQ -new $1 -keyout $NEWKEY -out $NEWREQ $DAYS $EXTRA{req}&quot;);</pre><p>and comment it out by adding the # symbol at the beginning of the line. Add the following two in its place:</p><pre>my $nodes_option = defined($1) ? $1 : &quot;&quot;;<br>$RET = run(&quot;$REQ -new $nodes_option -keyout $NEWKEY -out $NEWREQ $DAYS $EXTRA{req}&quot;);</pre><p>3. Save the file by typing :wq and try once again CSR generation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a956f5efed87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prepare a backup using the pgBackRest tool on an external volume mounted to the machine]]></title>
            <link>https://pbracha.medium.com/prepare-a-backup-using-the-pgbackrest-tool-on-an-external-volume-mounted-to-the-machine-99e5a45e9a05?source=rss-4f07f6d9363a------2</link>
            <guid isPermaLink="false">https://medium.com/p/99e5a45e9a05</guid>
            <category><![CDATA[pgbackrest]]></category>
            <dc:creator><![CDATA[Piotr Bracha]]></dc:creator>
            <pubDate>Mon, 17 Jun 2024 09:36:48 GMT</pubDate>
            <atom:updated>2024-07-30T19:38:52.177Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gevJNYThofXERspgA9Krmg.jpeg" /></figure><p>Today, effectively managing data and ensuring its security is critical for any organization. Backups are the foundation of any data protection strategy, offering various levels of protection and efficiency. In the context of PostgreSQL databases, the pgBackRest tool stands out as a powerful and comprehensive backup and management solution.</p><p>pgBackRest provides advanced features such as compression, encryption, replication and retention management that are essential for maintaining data integrity and availability. One of the most efficient ways to store backups is to use external volumes mounted to the machine, which allows for flexible disk space management and makes it easy to move data between different environments.</p><p>In this article, I will take you step-by-step through the process of configuring pgBackRest to create full and differential backups on an external volume created in DigitalOcean. I will discuss the configuration of the tool, the process of mounting an external volume, and best practices related to backup management. With this guide, you will be able to effectively protect your data and ensure the continuity of your PostgreSQL database, regardless of any failures or other unpredictable events.</p><h4>Copy space, that is an external volume</h4><p>The default created volume, which in the panel is attached to a given instance of the machine, also automatically mounts itself in the file system. The volumes, thanks to the systemd and udev configuration, are automatically mounted when the machine is rebooted and you don’t need to modify <strong>/etc/fstab</strong> for this purpose. Additional information is available in the <a href="https://docs.digitalocean.com/products/volumes/how-to/create/#automatically-format--mount">documentation</a>.</p><h4>Implementing the pgBackRest tool and performing backups</h4><ol><li>Installation of pgBackRest:</li></ol><pre>apt install pgbackrest</pre><p>2. Configuration in the <strong>/etc/pgbackrest.conf</strong> file:</p><pre>[global]<br>process-max=2<br>repo1-block=y<br>repo1-bundle=y<br>repo1-path=/mnt/volume_jonas_test_purposes/pg_backup<br>repo1-retention-full=1<br>repo1-retention-diff=2<br>#archive-timeout=120<br>start-fast=y<br> <br>[main]<br>pg1-path=/var/lib/postgresql/12/main<br> <br>#[global:archive-push]<br>#compress-level=3</pre><p><strong>process-max</strong> — the number of parallel processes creating a backup. The main purpose — to speed up the creation of backups. Tune to number of cpu cores.<br><strong>repo1-block</strong> — backup data is stored as a series of data blocks instead of full files. This allows more efficient data management, including deduplication and restoration of only changed data blocks.<br><strong>repo1-bundle</strong> — backup files are grouped and packaged together. This can improve the performance of I/O operations, especially for file systems that handle fewer, larger files better than a large number of small files.<br><strong>repo1-path</strong> — the path to the directory where the backups will be stored, requires permissions <em>750</em> and <em>postgres:postgres</em> on the <em>pg_backup</em> directory<br><strong>repo1-retention-full</strong> — storing of a given number of full backups<br><strong>repo1-retention-diff</strong> — storing a given number of differential backups<br><strong>start-fast</strong> — does not wait for checkpoint creation but forces it and starts the backup. Crucial in production environments where minimizing backup execution time is critical to maintaining high system availability.<br><strong>pg1-path</strong> — path to the postgres data directory<br><strong>compress-level</strong> — archive compression level<br><strong>archive-timeout</strong> — set maximum time, in seconds, to wait for each WAL segment to reach the pgBackRest archive repository. Default is 60s. Modify only when you see timeout in log file related with wal archiving.</p><p>3. Configuration in <strong>/etc/postgresql/12/main/postgresql.conf</strong>:</p><pre>archive_command = &#39;pgbackrest --stanza=main archive-push %p&#39;<br>archive_mode = on<br>max_wal_senders = 3<br>wal_level = replica<br>max_wal_size = 4GB  # default 1GB<br>min_wal_size = 1GB  # default 80MB</pre><p><strong>archive_command</strong> — command executed by PostgreSQL to archive WAL. In this example “%p” is a special token used in PostgreSQL that denotes the full path to the Write-Ahead Log (WAL) file to be archived.<br><strong>archive_mode</strong> — enable archive mode.<br><strong>max_wal_senders</strong> — number of maximum WAL sending processes.<br><strong>wal_level</strong> — the level of stored WAL data, i.e minimum, logical, replica.<br><strong>max_wal_size</strong> and <strong>min_wal_size</strong> — maximum and minimum size of WAL segments.</p><p>4. Cluster restart:</p><pre>systemctl restart postgresql@12-main</pre><p>5. Initialize <strong>“stanza”</strong> from the postgres user and checking the configuration:</p><pre>pgbackrest --stanza=main --log-level-console=info stanza-create<br>pgbackrest --stanza=main check</pre><p>6. Create backups — use proper combination (in my case I chose full and differential):</p><pre>pgbackrest --stanza=main --type=full backup --log-level-console=info # full backup<br>pgbackrest --stanza=main --type=diff backup --log-level-console=info # differential backup<br>pgbackrest --stanza=main --type=incr backup --log-level-console=info # incremental backup</pre><p>7. Checking the status of backups:</p><pre>pgbackrest --stanza=main info</pre><p>8. Create a crontab entry in the postgres user account:</p><pre># Full backup on Sunday at midnight with logging<br>0 0 * * 0 pgbackrest --stanza=main --type=full backup &gt; /var/log/pgbackrest/backup_full.log 2&gt;&amp;1<br> <br># Differential backup Monday to Saturday at midnight with logging<br>0 0 * * 1-6 pgbackrest --stanza=main --type=diff backup &gt; /var/log/pgbackrest/backup_diff.log 2&gt;&amp;1</pre><p>9. Create <strong>backup_diff</strong> and <strong>backup_full</strong> files with appropriate permissions:</p><pre>touch /var/log/pgbackrest/backup_full.log<br>touch /var/log/pgbackrest/backup_diff.log<br> <br>chmod 640 /var/log/pgbackrest/backup_diff.log<br>chmod 640 /var/log/pgbackrest/backup_full.log<br> <br>chown postgres:postgres /var/log/pgbackrest/backup_diff.log<br>chown postgres:postgres /var/log/pgbackrest/backup_full.log</pre><h4>Restoring from backup</h4><p>Here we have to stop for a moment, because there are three approaches related to data recovery. The first takes into consideration deleting data from the <strong>/var/lib/postgresql/12/main</strong> directory, and the second does not. Third is Point-in-Time Recovery or PITR. What is the difference and which option should you choose?</p><p>The first, classic way requires an empty cluster directory before running the recovery option.</p><p>The second way is to use the “<strong>delta” </strong>parameter, which does not require an empty cluster directory. It involves restoring only those files that have been changed. The sha-1 hash function for each file in the cluster is calculated, and if it differs from that for a particular file in the backup then such a file is restored. This is clearly written in <a href="https://pgbackrest.org/user-guide.html#restore/option-delta">the documentation in section 10.2 “Delta option</a>”.</p><p>The third is a Point in Time Recovery. PITR allows the WAL to be played from a backup to a specified lsn, time, transaction id, or recovery point. For common recovery scenarios time-based recovery is arguably the most useful. A typical recovery scenario is to restore a table that was accidentally dropped or data that was accidentally deleted.</p><p>In addition, it is worth using the option process-max=X, where you can try to substitute the number of CPU cores for X. At the time of recovery from the backup, the postgres cluster is disabled, so the machine has additional resources. Besides, we want to restore it to full capacity as soon as possible.</p><p><strong>First way: Delete data from the /var/lib/postgresql/12/main directory</strong></p><ol><li>Stop the cluster:</li></ol><pre>systemctl stop postgresql@12-main</pre><p>2. Delete the contents from the data directory:</p><pre>find /var/lib/postgresql/12/main -mindepth 1 -delete</pre><p>3. Run the command to recover the cluster:</p><pre>pgbackrest --stanza=main restore --log-level-console=info</pre><p>4. Start the cluster:</p><pre>systemctl start postgresql@12-main</pre><p>5. Cluster status verification:</p><pre>pg_lsclusters<br>systemctl status postgresql@12-main</pre><p><strong>Second way: Using the “delta” parameter</strong></p><ol><li>Stop the cluster:</li></ol><pre>systemctl stop postgresql@12-main</pre><p>2. Run the recovery command with the “delta” parameter:</p><pre>pgbackrest --stanza=main restore --log-level-console=info --delta</pre><p>3. Start the cluster:</p><pre>systemctl start postgresql@12-main</pre><p>4. Cluster status verification:</p><pre>pg_lsclusters<br>systemctl status postgresql@12-main</pre><p><strong>Third way: PITR</strong></p><p>1. Check in the postgresql logs what is the time of occurrence of the failure. The more accurate the time obtained the better.</p><p>2. Stop the cluster:</p><pre>systemctl stop postgresql@12-main</pre><p>3. Run the command to recover the data:</p><pre>pgbackrest --stanza=main --delta --type=time &quot;--target=2024-06-17 16:13:29&quot; --target-action=promote restore --log-level-console=info</pre><p><strong>type</strong> — specifies the type of restore. “time” means that the restore will be performed to a specific point in time (timestamp).<br><strong>target — </strong>specifies the exact point in time to which the database is to be restored. Used format from postgresql log file.<br><strong>target-action</strong> — defines the action to be taken when the restore point is reached. “promote” means that after restoring to a certain point in time, the database will be promoted to the primary role. This completes the restoration process and makes the database ready for use.</p><p>4. Start the cluster:</p><pre>systemctl start postgresql@12-main</pre><p>5. Cluster status verification:</p><pre>pg_lsclusters<br>systemctl status postgresql@12-main</pre><h4>Which option to use?</h4><p>Classically, “it depends.” You should certainly pay attention to several issues:</p><ol><li>Multiplicity of data changes</li></ol><p>If the data directory contains most of the current data and only a small number of files have been changed or corrupted, using “delta” will allow you to restore the copy faster, as only the changed files will be restored.</p><p>2. Size of the database</p><p>A large database, such as several hundred GB, could make it take too long to delete and fully restore.</p><p>3. Downtime</p><p>If downtime must be minimized “delta” can reduce the time needed to restore data.</p><p>On the other hand, each case should be considered individually and tested which option is better.</p><h4>Summary</h4><p>From the article, you could learn how to configure and use the pgbackrest tool to be able to take care of automated efficient database backup and restore from it.</p><p>More definitely interesting/useful information in the documentation → <a href="https://pgbackrest.org/user-guide.html">https://pgbackrest.org/user-guide.html</a></p><p>List of available commands of the pgBackRest tool → <a href="https://pgbackrest.org/command.html">https://pgbackrest.org/command.html</a></p><p>Configuration information in /etc/pgbackrest.conf → <a href="https://pgbackrest.org/configuration.html">https://pgbackrest.org/configuration.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99e5a45e9a05" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>