How to install PostgreSQL on a FreeBSD cloud server?

07-02-2024 03:14:59

PostgreSQL is a free, high-performance relational database system. It has detailed documentation and powerful features, making it suitable for use in large databases. This article is based on a FreeBSD 12 cloud server and introduces the installation method of PostgreSQL 12.

Update the pkg software library.

$ sudo pkg update

Download and install PostgreSQL server-side and client-side.

$ sudo pkg install postgresql12-server postgresql12-client

Set to start automatically with the system.

$ sudo sysrc postgresql_enable=yes

Initialize the database.

$ sudo service postgresql initdb

Start the database.

$ sudo service postgresql start

Switch to the default user of PostgreSQL.

$ sudo su - postgres

Change the password of the default user for PostgreSQL. Replace yourPassword with the required password.

psql -c "alter user postgres with password 'yourPassword'"

Create a database user with the username admin.

createuser admin

Create a database testdb with admin as the database user.

createdb testdb -O admin

Connect to the PostgreSQL command line.

psql

For more information, please refer to the official documentation of PostgreSQL.