Getting PostgreSQL running on HaikuOS

The past few days I have been experimenting with the Beta 1 release of HaikuOS. This is how I got PostgreSQL 9.3 to work after installing in from the HaikuDepot App. There is a PostgreSQL 9.6 version but I was not able to get it working. The 9.6 package seems to be incomplete. So for this article, we will use PostgreSQL 9.3 instead.

Install PostgreSQL

Install PostgreSQL 9.3 from HaikuDepot with the following steps.

1. Open HaikuDepot from the Application menu on Tracker.

2. In the Tools menu, select Refresh repositories.

3. In HaikuDepot, ensure that the check box next to Show only featured packages is empy and unchecked.

4. In the Search terms text box enter postgre. After a few seconds all the available PostgreSQL packages should be displayed.

5. In the list select postgresql. To the left of the Install button ensure the version is 9.3.5-2. If not, select the next postgresql in the list and see if it is version 9.3.5-2.

6. Click the Install button.

Initial PostgreSQL Setup for Haiku Beta 1

Steps below are based on PostgreSQL docs (here: https://www.postgresql.org/docs/9.3/creating-cluster.html) and are Haiku specific.

Steps Taken after installing PostgreSQL from HaikuDepot:

1. Create a new folder for PostgreSQL data in /boot/system/settings such as postgresql.

2. At a Terminal prompt, run the command: chmod 700 <path> such that <path> is the path created in step 1 above. For me it was chmod 700 /boot/system/settings/postgresql

3. At the Terminal, run the command initdb <path> such that <path> is the path to the folder created in step 1 above. For me it was initdb /boot/system/settings/postgresql.

If the initdb run is successful, then you should get a reply like this:

Success. You can now start the database server using:

    postgres -D /boot/system/settings/postgresql
or
    pg_ctl -D /boot/system/settings/postgresql -l logfile start

4. To verify it works, enter one of the commands provided. If successful, it should look something like this:

/boot/system/settings> postgres -D /boot/system/settings/postgresql

LOG:  setsockopt(IPV6_V6ONLY) failed: Operation not supported
LOG:  database system was shut down at 2018-12-18 20:19:32 GMT
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections

Testing PostgreSQL

To test PostgreSQL do the following:

1. Open another instance of the Terminal App.

2. At the Terminal prompt run: createdb mydb. If the new database was successfully created, there should be no message and you should be at the terminal prompt.

3. At the Terminal prompt run: psql mydb. This should take into the PostgreSQL command prompt.

Stopping PostgreSQL

To properly stop the PostgreSQL process, do the following tasks.

1. Open another instance for Terminal.
2. Use the ps command to find the first process ID that is running postgresql as shown below.

/boot/system/settings/postgres> ps

Team                                                                           Id  #Threads  Gid  Uid
/bin/postgres -D /boot/system/settings/postgres     1904        1    0    0
/bin/postgres -D /boot/system/settings/postgres     1906        1    0    0
/bin/postgres -D /boot/system/settings/postgres     1907        1    0    0
/bin/postgres -D /boot/system/settings/postgres     1908        1    0    0
/bin/postgres -D /boot/system/settings/postgres     1909        1    0    0
/bin/postgres -D /boot/system/settings/postgres     1910        1    0    0

At the Terminal prompt run: kill <pid> such that <pid> is the process ID. In the case above, the command would be: kill 1904

In the original Terminal where PostgreSQL was started, you should see something like this:

LOG:  received smart shutdown request
LOG:  autovacuum launcher shutting down
LOG:  shutting down
LOG:  database system is shut down

This indicates that PostgreSQL was properly shutdown.



Comments

  1. That's great! One more tool that could one day make it possible to do my work on Haiku. Waiting eagerly :)

    ReplyDelete

Post a Comment

Popular posts from this blog

AmigaOS Aros clone on Icaros Desktop version 2.2.5

FreeBSD and OpenBSD in Hyper-V - First Attempts

Recent AmigaOS 3.1 Word Processor Experiments