Install PostgreSQL on FreeBSD 12

Windows Articles

How to install Apache Maven on OpenSUSE 15.2 / 15.1?

In this post, we will show you how to install Apache Maven on OpenSUSE 15.2 / 15.1. To manage projects done in Java, there is...

How to install SQLite on OpenSUSE 15.2 / 15.1?

There are many good database management systems, but they are not all the same. And the fact that they are not, means...

How to detect port scanning and private IP access with Behave

Hello! Security when surfing the internet is a very serious issue. Consequently, the precautions we take are very important. Moreover, web browsers...

How to install LAMP on OpenSUSE 15.2 / 15.1?

It is increasingly common to find small companies that decide to use the SUSE ecosystem for their servers. It's an unsurprising decision because OpenSUSE...

How to use Mytop on Linux?

We already know that both MySQL and MariaDB are among the most popular database managers out there. They have earned this with...
angeloma
angeloma
Senior Writer and partner

To develop great applications you need a great database manager. So, that is why in this post I will teach you how to install PostgreSQL 12 on FreeBSD 12.

PostgreSQL

PostgreSQL is one of the most advanced and modern relational database managers out there. It is always shown as the immediate competitor of MySQL and MariaDB in the segment of open source and community database managers.

One of the main advantages of using PostgreSQL is that it has extensive documentation and supports powerful features. All this in an open-source and free application.

And recently version 12 has been released. If you want to know more about it read our post about it.

PostgreSQL 12.0 is available

This new version includes security improvements and interesting new features so it’s a good idea to install it.

So, let us start.

Install PostgreSQL on FreeBSD 12

In this guide, we will use commands that require you to be root. In this case, we will choose a user with privileges to use sudo. In case your user can’t do it, you can read our post.

How to enable sudo on FreeBSD 12.

If you are already the root user, you can simply remove the word sudo from the following commands.

The first step is to upgrade the system completely. To do this, open your FreeBSD terminal and run the following command:

:~$ sudo pkg update

After this, the system will be ready for work.

The goal of this post is to install PostgreSQL 12 on FreeBSD but in the official repositories, we have several versions of PostgeSQL.

:~$ sudo pkg search ^postgresql |grep -i server
postgresql10-server-10.11      PostgreSQL is the most advanced open-source database available anywhere
postgresql11-server-11.6       PostgreSQL is the most advanced open-source database available anywhere
postgresql12-server-12.1       PostgreSQL is the most advanced open-source database available anywhere
postgresql94-server-9.4.25     PostgreSQL is the most advanced open-source database available anywhere
postgresql95-server-9.5.20     PostgreSQL is the most advanced open-source database available anywhere
postgresql96-server-9.6.16     PostgreSQL is the most advanced open-source database available anywhere

1.- PostgreSQL on the FreeBSD repository
1.- PostgreSQL on the FreeBSD repository

The above command performs a search of the PostgreSQL package repositories but refines the search to server.

As you can see, versions 9.4, 9.5, 9.6,10,11 and 12 are available. Let’s install the version 12. To do so, run the following:

:~$ sudo pkg install postgresql12-server
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 5 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	postgresql12-server: 12.1
	icu: 65.1,1
	postgresql12-client: 12.1
	perl5: 5.30.1
	readline: 8.0.1

Number of packages to be installed: 5

The process will require 141 MiB more space.
31 MiB to be downloaded.

Proceed with this action? [y/N]:

2.- Install PostgreSQL on FreeBSD 12
2.- Install PostgreSQL on FreeBSD 12

Then, the installation will start normally.

3.- Installation is finished
3.- Installation is finished

Once the installation is complete, the first thing to do is to get PostgreSQL started with the system. This is not mandatory but it is convenient in many cases.

So to do this, edit the /etc/rc.conf file

:~$ sudo nano /etc/rc.conf

Now add the following:

postgresql_enable="YES"

4.- Enabling the PostgreSQL service
4.- Enabling the PostgreSQL service

Save the changes and close the file. In case you don’t have nano installed, you can do it with the following command:

:~$ sudo pkg install nano

Before starting the PostgreSQL service the default database must be initialized. To do this, run the following command:

:~$ sudo service postgresql initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /var/db/postgres/data12 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... America/Caracas
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/local/bin/pg_ctl -D /var/db/postgres/data12 -l logfile start

5.- Configuring PostgreSQL
5.- Configuring PostgreSQL

And now you can start the PostgreSQL service with the following command:

:~$ sudo service postgresql start
2020-02-05 14:52:37.731 -04 [869] LOG:  starting PostgreSQL 12.1 on amd64-portbld-freebsd12.0, compiled by FreeBSD clang version 6.0.1 (tags/RELEASE_601/final 335540) (based on LLVM 6.0.1), 64-bit
2020-02-05 14:52:37.732 -04 [869] LOG:  listening on IPv6 address "::1", port 5432
2020-02-05 14:52:37.732 -04 [869] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2020-02-05 14:52:37.735 -04 [869] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2020-02-05 14:52:37.749 -04 [869] LOG:  ending log output to stderr
2020-02-05 14:52:37.749 -04 [869] HINT:  Future log output will go to log destination "syslog".

5.- Starting the service
5.- Starting the service

Finally, access the PostgreSQL console with the following command:

:~$ sudo -u postgres psql

6.- PostgreSQL properly running on FreeBSD 12
6.- PostgreSQL properly running on FreeBSD 12

As you can see you can already use PostgreSQL 12 on FreeBSD without problems.

Conclusion

PostgreSQL is perhaps the best open source database manager and this consideration has not been given away. It has been earned with many jobs and above all with extraordinary performance. Now you know how to install it on FreeBSD 12.

Share this post and join our Telegram channel.

More articles

2 COMMENTS

  1. Excellent Article! It worked great for me. I had to do a few minor adjustments but overall, it worked like a charm.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to install Apache Maven on OpenSUSE 15.2 / 15.1?

In this post, we will show you how to install Apache Maven on OpenSUSE 15.2 / 15.1. To manage projects done in Java, there is...

How to install SQLite on OpenSUSE 15.2 / 15.1?

There are many good database management systems, but they are not all the same. And the fact that they are not, means...

How to detect port scanning and private IP access with Behave

Hello! Security when surfing the internet is a very serious issue. Consequently, the precautions we take are very important. Moreover, web browsers...

How to install LAMP on OpenSUSE 15.2 / 15.1?

It is increasingly common to find small companies that decide to use the SUSE ecosystem for their servers. It's an unsurprising decision because OpenSUSE...

How to use Mytop on Linux?

We already know that both MySQL and MariaDB are among the most popular database managers out there. They have earned this with...