SoFunction
Updated on 2025-04-07

FREEBSD Installation POSTGRESQL Notes

After a long time of struggle, I reinitialized many times.

During installation, the command: pkg search postgresql. Uh, there are many packages, choose the latest 9.4 installation server, and the client will be installed together. There will be many text prompts after installation, which is very useful. After installation, a new user pgsql will be created, and the home directory is /usr/local/pgsql.

first step

You must first switch to pgsql user, su root, su pgsql. Then create a data folder in the pgsql home directory. It seems that it is not allowed under root user
Initdb -D /usr/local/pgsql/data/ , many files will be generated. Initializing the database storage area will automatically create a postgres database, which will put a mess of settings and data from third-party plug-ins. There will also be a template template1. It is not very clear here, and you will use this template to create a database in the future. What we want to talk about here is the problem of database encoding. The tragedy has been initialized many times here.
After executing the above command by default, the prompt text will tell you (I didn't read it at the time.) The default database encoding is "sql_ascii", and the default text search is set to english. . When I was relying on execution, I stared at the screen in a daze, just waiting for the execution to be completed. . . I also saw the method of reinitialization from the prompts. Initdb will prompt you to clear the original folder or create it. Direct rm -rf *.initdb –help
You can see that the character encoding settings are -encoding ,initdb -encoding=UTF8 -D /usr/local/pgsql/data/

Start postgresql and start the script /usr/local/etc//postgresql. There are also hints to add to /etc/ file at the beginning.
status not running,start succeed

Create database, createb –encoding=UTF-8 bt, use client connection, qsql bt,
After entering, show server_encoding; check server encoding, utf8
\encoding View client encoding. The client is still SQL_ASCII, and you can use /encoding utf8 to change the client encoding.
You can also use \l to view it directly.

OK, there is basically no other problem.