install_pgsql_cod_fonte
Differences
This shows you the differences between two versions of the page.
| install_pgsql_cod_fonte [2025/07/26 17:09] – - Imported by DokuWiki Advanced Plugin wikiadm | install_pgsql_cod_fonte [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Instalação por código fonte - Debian ====== | ||
| - | ===== Vagranfile ===== | ||
| - | <file ruby Vagrantfile> | ||
| - | $ cat Vagrantfile | ||
| - | # -*- mode: ruby -*- | ||
| - | # vi: set ft=ruby : | ||
| - | |||
| - | ENV[' | ||
| - | |||
| - | vms = { | ||
| - | " | ||
| - | " | ||
| - | } | ||
| - | |||
| - | Vagrant.configure(" | ||
| - | |||
| - | config.vm.box_check_update = false | ||
| - | |||
| - | vms.each do |name, conf| | ||
| - | |||
| - | config.vm.define "# | ||
| - | |||
| - | vms.vm.network : | ||
| - | vms.vm.box = "# | ||
| - | vms.vm.hostname = "# | ||
| - | |||
| - | vms.vm.provider :libvirt do |lv| | ||
| - | lv.memory = conf[" | ||
| - | lv.cpus = conf[" | ||
| - | lv.cpu_mode = " | ||
| - | lv.cputopology :sockets => " | ||
| - | lv.disk_driver :cache => " | ||
| - | if name == ' | ||
| - | lv.storage :file, :size => ' | ||
| - | end | ||
| - | end | ||
| - | end | ||
| - | end | ||
| - | config.vm.synced_folder " | ||
| - | end | ||
| - | </ | ||
| - | |||
| - | ===== Arquitetura de diretórios sugerida ===== | ||
| - | ^Tipo^Localização^ | ||
| - | |Instalação|/ | ||
| - | |Configuração|/ | ||
| - | |Dados (PGDATA)|/ | ||
| - | |Binários|/ | ||
| - | ===== Preparando partição para a instalação do PodtgreSQL ===== | ||
| - | |||
| - | <file bash> | ||
| - | vagrant@pgsql-director: | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director: | ||
| - | Disco /dev/vda: 32 GiB, 34359738368 bytes, 67108864 setores | ||
| - | Unidades: setor de 1 * 512 = 512 bytes | ||
| - | Tamanho de setor (lógico/ | ||
| - | Tamanho E/S (mínimo/ | ||
| - | Tipo de rótulo do disco: dos | ||
| - | Identificador do disco: 0x5c4d2e13 | ||
| - | |||
| - | Dispositivo Inicializar | ||
| - | / | ||
| - | / | ||
| - | / | ||
| - | |||
| - | |||
| - | Disco /dev/vdb: 32 GiB, 34359738368 bytes, 67108864 setores | ||
| - | Unidades: setor de 1 * 512 = 512 bytes | ||
| - | Tamanho de setor (lógico/ | ||
| - | Tamanho E/S (mínimo/ | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director: | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director: | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director: | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director: | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director: | ||
| - | --- Logical volume --- | ||
| - | LV Path / | ||
| - | LV Name lvPGSQL | ||
| - | VG Name vgPGSQL | ||
| - | LV UUID nCKWWy-9O4E-pwvk-VwdT-w9uK-xTd8-Eo8j7K | ||
| - | LV Write Access | ||
| - | LV Creation host, time pgsql-director, | ||
| - | LV Status | ||
| - | # open 0 | ||
| - | LV Size <27,20 GiB | ||
| - | Current LE 6962 | ||
| - | Segments | ||
| - | Allocation | ||
| - | Read ahead sectors | ||
| - | - currently set to 256 | ||
| - | Block device | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director: | ||
| - | mke2fs 1.46.2 (28-Feb-2021) | ||
| - | Discarding device blocks: done | ||
| - | Creating filesystem with 7129088 4k blocks and 1782368 inodes | ||
| - | Filesystem UUID: 66f3cbfc-5ea2-4058-929d-476b8aee88fd | ||
| - | Superblock backups stored on blocks: | ||
| - | 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, | ||
| - | 4096000 | ||
| - | |||
| - | Allocating group tables: done | ||
| - | Writing inode tables: done | ||
| - | Creating journal (32768 blocks): done | ||
| - | Writing superblocks and filesystem accounting information: | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director: | ||
| - | root@pgsql-director: | ||
| - | root@pgsql-director: | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director: | ||
| - | UUID=66f3cbfc-5ea2-4058-929d-476b8aee88fd | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director: | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director: | ||
| - | Sist. Arq. Tam. Usado Disp. Uso% Montado em | ||
| - | udev | ||
| - | tmpfs 394M 428K 393M 1% /run | ||
| - | / | ||
| - | tmpfs 2,0G | ||
| - | tmpfs 5,0M | ||
| - | tmpfs 394M | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | ===== Vatiáveis de ambiente de pacotes ===== | ||
| - | <file bash> | ||
| - | # Pacotes a serem removidos após a instalação | ||
| - | PKG_RM=' | ||
| - | # Pacotes a serem mantidos: | ||
| - | # Pacotes comuns a serem mantidos: | ||
| - | PKG=' | ||
| - | # Variável de ambiente para pacotes Debian: | ||
| - | PKG_DEB=" | ||
| - | uuid-dev python3-dev" | ||
| - | </ | ||
| - | |||
| - | ==== Instalação de pacotes e limpeza dos pacotes baixados ==== | ||
| - | <file bash> | ||
| - | apt update && apt install -y ${PKG} ${PKG_RM} ${PKG_DEB} && apt clean | ||
| - | </ | ||
| - | |||
| - | ==== Habilitar configurações de localidades (locales) pt_BR.utf8 e en_US.utf8 ==== | ||
| - | <file bash> | ||
| - | sed -i -e 's/# en_US.UTF-8 UTF-8/ | ||
| - | sed -i -e 's/# pt_BR.UTF-8 UTF-8/ | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | locale-gen | ||
| - | </ | ||
| - | |||
| - | ===== Definição de variáveis gerais ===== | ||
| - | <file bash> | ||
| - | # Variável de ambiente para versão completa do Postgres via prompt: | ||
| - | read -p \ | ||
| - | ' | ||
| - | PGVERSION | ||
| - | # Definição da variável de ambiente para a versão majoritária: | ||
| - | export PGMAJOR=`echo ${PGVERSION} | cut -f1 -d.` | ||
| - | # Diretório de instalação do PostgreSQL | ||
| - | PGHOME="/ | ||
| - | # Diretório de binários | ||
| - | PGBIN=" | ||
| - | # Diretório home do usuário postgres | ||
| - | PGUSERHOME="/ | ||
| - | # Diretório de logs | ||
| - | PGLOG="/ | ||
| - | # Diretório de dados do PostgreSQL | ||
| - | PGDATA=" | ||
| - | # Diretório de logs de transação | ||
| - | PGWAL=" | ||
| - | # Diretório de estatísticas temporárias | ||
| - | PG_STAT_TEMP=" | ||
| - | # Diretório de headers C | ||
| - | PGINCLUDEDIR="/ | ||
| - | </ | ||
| - | |||
| - | [[https:// | ||
| - | |||
| - | ===== Variáveis de ambiente para o processo de compilação ===== | ||
| - | <file bash> | ||
| - | # Variável de ambiente do executável Python 3 | ||
| - | export PYTHON=`which python3` | ||
| - | # Opções do configure | ||
| - | CONFIGURE_OPTS=" | ||
| - | --prefix=${PGHOME} \ | ||
| - | --with-python \ | ||
| - | --with-libxml \ | ||
| - | --with-openssl \ | ||
| - | --with-ldap \ | ||
| - | --with-uuid=e2fs \ | ||
| - | --includedir=${PGINCLUDEDIR}" | ||
| - | # Protege o processo principal do OOM Killer | ||
| - | CPPFLAGS=" | ||
| - | # Número de jobs conforme a quantidade de cores da CPU (cores + 1): | ||
| - | NJOBS=`expr \`nproc\` + 1` | ||
| - | # Opções do make | ||
| - | MAKEOPTS=" | ||
| - | # Tipo de hardware | ||
| - | CHOST=" | ||
| - | # Flags de otimização para o make | ||
| - | CFLAGS=" | ||
| - | CXXFLAGS=" | ||
| - | </ | ||
| - | |||
| - | ==== Criação de um grupo e usuário de sistema ==== | ||
| - | |||
| - | <file bash> | ||
| - | groupadd -r postgres &> /dev/null | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | useradd \ | ||
| - | -c ' | ||
| - | -s /bin/bash \ | ||
| - | -k /etc/skel \ | ||
| - | -d ${PGUSERHOME} \ | ||
| - | -g postgres \ | ||
| - | -m -r postgres &> /dev/null | ||
| - | </ | ||
| - | |||
| - | ==== Criar o arquivo .pgvars com seu respectivo conteúdo no diretório do usuário home postgres ==== | ||
| - | <file bash> | ||
| - | cat << EOF > ~postgres/ | ||
| - | # Environment Variables ====================================================== | ||
| - | # PostgreSQL major version | ||
| - | PGMAJOR=" | ||
| - | # Postgre=SQL installation directory | ||
| - | PGHOME="/ | ||
| - | # Binary directory | ||
| - | PGBIN=" | ||
| - | # Library directories | ||
| - | export LD_LIBRARY_PATH=" | ||
| - | # Manuals directories | ||
| - | export MANPATH=" | ||
| - | # Path to binaries | ||
| - | export PATH=" | ||
| - | # PostgreSQL data directory | ||
| - | export PGDATA=" | ||
| - | # Unset variables | ||
| - | unset PGMAJOR PGHOME PGBIN | ||
| - | EOF | ||
| - | </ | ||
| - | |||
| - | ==== Adiciona linha no arquivo de perfil do usuário postgres para ler o arquivo ~/.pgvars e aplicá-las ==== | ||
| - | <file bash> | ||
| - | if [ -f ~postgres/ | ||
| - | echo -e " | ||
| - | else | ||
| - | echo -e " | ||
| - | fi | ||
| - | </ | ||
| - | |||
| - | ==== ~postgres/ | ||
| - | <file bash> | ||
| - | cat << EOF > ~postgres/ | ||
| - | \set HISTCONTROL ignoreboth | ||
| - | \set COMP_KEYWORD_CASE upper | ||
| - | \x auto | ||
| - | EOF | ||
| - | </ | ||
| - | |||
| - | ===== Criação de diretórios ===== | ||
| - | <file bash> | ||
| - | mkdir -pm 0700 ${PGLOG} ${PGDATA} ${PGWAL} ${PG_STAT_TEMP} | ||
| - | </ | ||
| - | |||
| - | ==== Download do código-fonte ==== | ||
| - | <file bash> | ||
| - | wget -c \ | ||
| - | https:// | ||
| - | ${PGVERSION}.tar.bz2 -P /tmp/ | ||
| - | </ | ||
| - | |||
| - | === Ir para /tmp onde o arquivo foi baixado, descompactá-lo === | ||
| - | <file bash> | ||
| - | cd /tmp/ && tar xf postgresql-${PGVERSION}.tar.bz2 | ||
| - | </ | ||
| - | |||
| - | === Após a descompactação acessar a pasta do código-fonte === | ||
| - | <file bash> | ||
| - | cd postgresql-${PGVERSION} | ||
| - | </ | ||
| - | |||
| - | === Processo de configure === | ||
| - | <file bash> | ||
| - | ./configure ${CONFIGURE_OPTS} | ||
| - | </ | ||
| - | |||
| - | === Compilação (com manuais e contrib) === | ||
| - | <file bash> | ||
| - | make world | ||
| - | </ | ||
| - | |||
| - | === Instalação === | ||
| - | <file bash> | ||
| - | make install-world | ||
| - | </ | ||
| - | |||
| - | === Criação de arquivo de serviço SystemD do PostgreSQL === | ||
| - | <file bash> | ||
| - | cat << EOF > / | ||
| - | [Unit] | ||
| - | Description=PostgreSQL ${PGMAJOR} database server | ||
| - | After=syslog.target | ||
| - | After=network.target | ||
| - | [Service] | ||
| - | Type=forking | ||
| - | User=postgres | ||
| - | Group=postgres | ||
| - | Environment=PGDATA=" | ||
| - | Environment=LD_LIBRARY_PATH=" | ||
| - | OOMScoreAdjust=-1000 | ||
| - | ExecStart=${PGBIN}/ | ||
| - | ExecStop=${PGBIN}/ | ||
| - | ExecReload=${PGBIN}/ | ||
| - | TimeoutSec=300 | ||
| - | [Install] | ||
| - | WantedBy=multi-user.target | ||
| - | EOF | ||
| - | </ | ||
| - | |||
| - | === Dar propriedade ao usuário e grupo postgres aos diretórios === | ||
| - | |||
| - | <file bash> | ||
| - | chown -R postgres: / | ||
| - | </ | ||
| - | |||
| - | === Criação de cluster (instância) === | ||
| - | <file bash> | ||
| - | su - postgres -c "\ | ||
| - | initdb \ | ||
| - | -D ${PGDATA} \ | ||
| - | -E utf8 \ | ||
| - | -U postgres \ | ||
| - | -k \ | ||
| - | --locale=pt_BR.utf8 \ | ||
| - | --lc-collate=pt_BR.utf8 \ | ||
| - | --lc-monetary=pt_BR.utf8 \ | ||
| - | --lc-messages=en_US.utf8 \ | ||
| - | -T portuguese \ | ||
| - | -X ${PGWAL}" | ||
| - | </ | ||
| - | |||
| - | === Alterações no postgresql.conf via sed === | ||
| - | <file bash> | ||
| - | # listen_addresses = ' | ||
| - | sed " | ||
| - | -i ${PGDATA}/ | ||
| - | # log_destination = ' | ||
| - | sed " | ||
| - | -i ${PGDATA}/ | ||
| - | # logging_collector = on | ||
| - | sed " | ||
| - | -i ${PGDATA}/ | ||
| - | # log_filename (nova linha descomentada) | ||
| - | sed " | ||
| - | -i ${PGDATA}/ | ||
| - | # log_directory = ' | ||
| - | sed " | ||
| - | -i ${PGDATA}/ | ||
| - | # stats_temp_directory = ' | ||
| - | sed \ | ||
| - | " | ||
| - | -i ${PGDATA}/ | ||
| - | </ | ||
| - | |||
| - | === Montagem da linha para montagem em memória RAM === | ||
| - | |||
| - | <file bash> | ||
| - | echo -e \ | ||
| - | " | ||
| - | >> /etc/fstab | ||
| - | </ | ||
| - | |||
| - | === Monta tudo definido em /etc/fstab === | ||
| - | <file bash> | ||
| - | mount -a | ||
| - | </ | ||
| - | |||
| - | === Habilita e inicializa o serviço do PostgreSQL === | ||
| - | <file bash> | ||
| - | systemctl enable --now postgresql-${PGMAJOR} | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | oot@pgsql-director:/ | ||
| - | ● postgresql-14.service - PostgreSQL 14 database server | ||
| - | | ||
| - | | ||
| - | Process: 17766 ExecStart=/ | ||
| - | Main PID: 17769 (postgres) | ||
| - | Tasks: 8 (limit: 4678) | ||
| - | | ||
| - | CPU: 109ms | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | |||
| - | dez 08 18:08:17 pgsql-director systemd[1]: Starting PostgreSQL 14 database server... | ||
| - | dez 08 18:08:18 pgsql-director pg_ctl[17769]: | ||
| - | dez 08 18:08:18 pgsql-director pg_ctl[17769]: | ||
| - | dez 08 18:08:18 pgsql-director systemd[1]: Started PostgreSQL 14 database server. | ||
| - | </ | ||
| - | |||
| - | ===== TimescaleDB ===== | ||
| - | <file bash> | ||
| - | git clone https:// | ||
| - | cd timescaledb | ||
| - | git checkout 2.8.1 | ||
| - | ./bootstrap -DPG_CONFIG=/ | ||
| - | cd build && make | ||
| - | make install | ||
| - | </ | ||
| - | |||
| - | [[https:// | ||
| - | |||
| - | <file bash> | ||
| - | sed " | ||
| - | -i ${PGDATA}/ | ||
| - | </ | ||
| - | ===== Limpeza de pacote desnecessários ===== | ||
| - | <file bash> | ||
| - | apt purge -y ${PKG_RM} ${PKG_DEB} | ||
| - | </ | ||
| - | |||
| - | ===== Testando o acesso ===== | ||
| - | |||
| - | <file bash> | ||
| - | root@pgsql-director:/ | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | postgres@pgsql-director: | ||
| - | Expanded display is used automatically. | ||
| - | psql (14.6) | ||
| - | Type " | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | postgres=# SELECT version(); | ||
| - | version | ||
| - | --------------------------------------------------------------------------------------------------- | ||
| - | | ||
| - | (1 row) | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | postgres=# \l | ||
| - | List of databases | ||
| - | | ||
| - | -----------+----------+----------+------------+------------+----------------------- | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | (3 rows) | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | postgres=# \q | ||
| - | postgres@pgsql-director: | ||
| - | sair | ||
| - | </ | ||
| - | |||
| - | ===== Referências ===== | ||
| - | * [[https:// | ||
| - | * [[https:// | ||
install_pgsql_cod_fonte.1753560544.txt.gz · Last modified: by wikiadm
