===== Procedimento para instalar o BD Postgres no FreeBSD =====
=== 1 - Vamos atualizar o ports e o pkg: ===
# pkg update
# portsnap fetch extract
=== 2 - Agora vou instalar a última versão do postgres disponível na versão 13.1: ===
# pkg install postgresql15-server-15.1_1
=== 3 - Após o termino da instalação, vamos ativar o postgres no /etc/rc.conf: ===
# /usr/local/etc/rc.d/postgresql enable
postgresql enabled in /etc/rc.conf
=== 4 - Agora vamos construir os arquivos do banco com o comando abaixo: ===
# 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 this locale configuration:
provider: libc
LC_COLLATE: C
LC_CTYPE: C.UTF-8
LC_MESSAGES: C.UTF-8
LC_MONETARY: C.UTF-8
LC_NUMERIC: C.UTF-8
LC_TIME: C.UTF-8
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /var/db/postgres/data15 ... 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/Belem
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
initdb: hint: 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/data15 -l logfile start
=== 5 - Vamos iniciar o serviço: ===
# /usr/local/etc/rc.d/postgresql start
2023-03-29 17:45:38.216 -03 [14795] LOG: ending log output to stderr
2023-03-29 17:45:38.216 -03 [14795] HINT: Future log output will go to log destination "syslog".
=== 6 - Vamos configurar uma senha para o usuário postgres: ===
# su - postgres
$
$ psql
psql (15.1)
Type "help" for help.
postgres=#
postgres=# ALTER USER postgres WITH PASSWORD 'sua_senha_aqui';
ALTER ROLE
=== 7 - Para configurar as permissões de acesso remoto ao banco, você pode configurar o arquivo /var/db/postgres/data15/pg_hba.conf: ===
-- Por exemplo, procure as linhas abaixo:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
OBS: Nas linhas acima você irá configurar os IPs que podem acessar seu banco e o método de autenticação. No meu caso, vou dar um exemplo liberando o acesso vindo de qualquer rede com autenticação por senha:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
#host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5 # Modificada
# IPv6 local connections:
#host all all ::1/128 trust
host all all ::1/128 md5 # Modificada
OBS: As linhas modificadas em questão especificam uma regra de acesso para clientes que se conectam ao servidor usando o protocolo "host", permitindo que todos os usuários (representados por "all") se conectem a todos os bancos de dados (também "all") a partir de qualquer endereço IP (representado por "0.0.0.0/0"). A autenticação será realizada usando o método "md5", que é uma forma segura de autenticação baseada em senha que armazena as senhas como um hash criptográfico em vez de texto simples.
=== 8 - Após as auterações, reinicie o serviço do banco de dados e pode efetuar os testes com seu cliente: ===
# /usr/local/etc/rc.d/postgresql restart
2023-03-31 17:24:19.626 -03 [97839] LOG: ending log output to stderr
2023-03-31 17:24:19.626 -03 [97839] HINT: Future log output will go to log destination "syslog".
-----------------
~~DISCUSSION|Deixe sua contribuição~~