{"id":2784,"date":"2026-01-08T22:28:29","date_gmt":"2026-01-08T13:28:29","guid":{"rendered":"https:\/\/www.next-hop.net\/blog\/hiraga\/?p=2784"},"modified":"2026-01-11T04:19:07","modified_gmt":"2026-01-10T19:19:07","slug":"install-postgresql","status":"publish","type":"post","link":"https:\/\/www.next-hop.net\/blog\/hiraga\/freebsd\/install-postgresql\/","title":{"rendered":"PostgreSQL \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b"},"content":{"rendered":"<p>FreeBSD\u306bPostgreSQL\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<br \/>\n17.7\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5bfe\u8c61\u3068\u3057\u3066\u3044\u307e\u3059\u304c\u300118\u3067\u3082\u57fa\u672c\u7684\u306b\u306f\u540c\u3058\u3067\u3059\u3002<br \/>\n\u305f\u3060\u3057\u3001\u30c1\u30a7\u30c3\u30af\u30b5\u30e0\u304c18\u3067\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u6709\u52b9\u3068\u306a\u308a\u307e\u3057\u305f\u306e\u3067\u300118\u4ee5\u524d\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3068\u304d\u306b\u3082\u6700\u521d\u304b\u3089\u30c1\u30a7\u30c3\u30af\u30b5\u30e0\u3092\u6709\u52b9\u306b\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<h2>\u524d\u63d0<\/h2>\n<ul>\n<li>FreeBSD 13.5<\/li>\n<li>PostgreSQL 17.7<\/li>\n<\/ul>\n<h2>\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npkg install -y postgresql17-server\r\n<\/pre>\n<h3>\u30ed\u30b1\u30fc\u30eb\u8a2d\u5b9a<\/h3>\n<h4>\/etc\/login.conf<\/h4>\n<pre class=\"brush: diff; title: ; notranslate\" title=\"\">\r\n+ postgres:\\\r\n+         :lang=en_US.UTF-8:\\\r\n+         :setenv=LC_COLLATE=C:\\\r\n+         :tc=default:\r\n<\/pre>\n<h4>\u53cd\u6620<\/h4>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncap_mkdb \/etc\/login.conf\r\n<\/pre>\n<h3>\u8d77\u52d5\u8a2d\u5b9a<\/h3>\n<p>\u30c7\u30fc\u30bf\u306e\u30c1\u30a7\u30c3\u30af\u30b5\u30e0\u3092\u6709\u52b9\u306b\u3057\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u521d\u671f\u5316\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsysrc postgresql_login_class=postgres\r\nsysrc postgresql_initdb_flags=&quot;--encoding=utf-8 --lc-collate=C --data-checksums&quot;\r\nsysrc postgresql_enable=YES\r\nservice postgresql initdb\r\n<\/pre>\n<h3>\u8d77\u52d5<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nservice postgresql start\r\n<\/pre>\n<h3>\u52d5\u4f5c\u78ba\u8a8d<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsu postgres -c &quot;psql --version&quot;\r\npsql (PostgreSQL) 17.7\r\n<\/pre>\n<h2>Ansible playbook<\/h2>\n<h4>install_postgresql.yaml<\/h4>\n<pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\r\n---\r\n- name: Install and configure PostgreSQL on FreeBSD\r\n  hosts: postgresql.example.com\r\n  become: yes\r\n  gather_facts: false\r\n  vars:\r\n    pg_ver: 17\r\n\r\n  tasks:\r\n    - name: Install PostgreSQL {{ pg_ver }} server package\r\n      community.general.pkgng:\r\n        name: &quot;postgresql{{ pg_ver }}-server&quot;\r\n        state: present\r\n\r\n    - name: Ensure postgres login class exists in \/etc\/login.conf\r\n      blockinfile:\r\n        path: \/etc\/login.conf\r\n        block: |\r\n          postgres:\\\r\n                  :lang=en_US.UTF-8:\\\r\n                  :setenv=LC_COLLATE=C:\\\r\n                  :tc=default:\r\n        marker: &quot;# {mark} ANSIBLE POSTGRES LOGIN CLASS&quot;\r\n\r\n    - name: Rebuild login.conf database\r\n      command: cap_mkdb \/etc\/login.conf\r\n      changed_when: false\r\n\r\n    - name: Set postgresql login class\r\n      community.general.sysrc:\r\n        name: postgresql_login_class\r\n        value: postgres\r\n\r\n    - name: Set initdb flags for PostgreSQL &lt;=17\r\n      community.general.sysrc:\r\n        name: postgresql_initdb_flags\r\n        value: &#039;--encoding=utf-8 --lc-collate=C --data-checksums&#039;\r\n      when: pg_ver | int &lt; 18\r\n      changed_when: false\r\n\r\n    - name: Set initdb flags for PostgreSQL 18+\r\n      community.general.sysrc:\r\n        name: postgresql_initdb_flags\r\n        value: &#039;--encoding=utf-8 --lc-collate=C&#039;\r\n      when: pg_ver | int &gt;= 18\r\n      changed_when: false\r\n\r\n    - name: Enable PostgreSQL service\r\n      community.general.sysrc:\r\n        name: postgresql_enable\r\n        value: &quot;YES&quot;\r\n\r\n    - name: Initialize PostgreSQL database\r\n      command: service postgresql initdb\r\n      args:\r\n        creates: &quot;\/var\/db\/postgres\/data{{ pg_ver }}\/PG_VERSION&quot;\r\n\r\n    - name: Start PostgreSQL service\r\n      service:\r\n        name: postgresql\r\n        state: started\r\n        enabled: yes\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>FreeBSD\u306bPostgreSQL\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002 17.7\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5bfe\u8c61\u3068\u3057\u3066\u3044\u307e\u3059\u304c\u300118\u3067\u3082\u57fa\u672c\u7684\u306b\u306f\u540c\u3058\u3067\u3059\u3002 \u305f\u3060\u3057\u3001\u30c1\u30a7\u30c3\u30af\u30b5\u30e0\u304c18\u3067\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u6709\u52b9\u3068\u306a\u308a\u307e\u3057\u305f\u306e\u3067\u300118\u4ee5\u524d\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.next-hop.net\/blog\/hiraga\/freebsd\/install-postgresql\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2784","post","type-post","status-publish","format-standard","hentry","category-freebsd"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/posts\/2784"}],"collection":[{"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/comments?post=2784"}],"version-history":[{"count":8,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/posts\/2784\/revisions"}],"predecessor-version":[{"id":2847,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/posts\/2784\/revisions\/2847"}],"wp:attachment":[{"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/media?parent=2784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/categories?post=2784"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/tags?post=2784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}