<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JugglerShu.Net &#187; postgresql</title>
	<atom:link href="http://programming.jugglershu.net/wp/?cat=32&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://programming.jugglershu.net/wp</link>
	<description>Nothing But Programming</description>
	<lastBuildDate>Wed, 15 Apr 2020 08:11:15 +0000</lastBuildDate>
	<language>ja</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>Postgresに外部から接続</title>
		<link>http://programming.jugglershu.net/wp/?p=638</link>
		<comments>http://programming.jugglershu.net/wp/?p=638#comments</comments>
		<pubDate>Sun, 15 Feb 2009 08:23:00 +0000</pubDate>
		<dc:creator><![CDATA[shu]]></dc:creator>
				<category><![CDATA[pg_hba.conf]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[postgresql.conf]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://programming.jugglershu.net/wp/?p=638</guid>
		<description><![CDATA[mysqlよりちょっと難しかったのでメモ。 環境- CentOS5- Postgres 8.1.1 とりあえず初期設定はpostgresユーザーになって、initdbを行う。DB用フォルダは自分で-Dオプションで指定してもいいし、環境変数PGDATAに入れておいてもいいらしい。とりあえずCentOS5で標準でインストールされているPosgtresを使うと、postgresユーザーの.bash_pr <a class="more-link" href="http://programming.jugglershu.net/wp/?p=638">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>mysqlよりちょっと難しかったのでメモ。</p>
<p>環境<br />- CentOS5<br />- Postgres 8.1.1</p>
<p>とりあえず初期設定は<br />postgresユーザーになって、initdbを行う。DB用フォルダは自分で-Dオプションで指定してもいいし、環境変数PGDATAに入れておいてもいいらしい。とりあえずCentOS5で標準でインストールされているPosgtresを使うと、postgresユーザーの.bash_profileにすでに環境変数が登録されているので、そのままにしておいた。</p>
<p>その後はrootユーザーでservice postgresql startなどのコマンドで起動。</p>
<p>とりあえずそのlocalhostからpsqlで接続。psql -U postgres でよい。これで接続できればとりあえずPostgresサーバーは動いている。<br />ここまでは簡単だった。</p>
<p>次に外部からの接続設定。<br />今回は、192.168.1.0ネットワークでPostgresサーバーが192.168.10で動いているものとする。<br />設定箇所は２か所。DB用フォルダの中にpostgresql.confとpg_hba.confがある。(CentOSの場合 /var/lib/pgsql/dataが標準の場所)<br />postgresql.confがサーバー全体の設定で、pg_hba.confが接続許可設定という感じだと思う。</p>
<p>まず、postgresql.confでlisten_addressの行を変更する。これはどのIPアドレスで接続待ちをするかの設定。接続を許可するIPアドレスとは異なるので注意。一回間違えた。というわけでサーバー側のIPアドレスを指定。デフォルトだとlocalhostとなっているため、192.168.1.10に変更するか、&#8221;*&#8221;(all)にしてしまう。<br />listen_address = &#8220;*&#8221;<br />というかんじ。<br />これで192.168.1.10で待ち受けてくれる。</p>
<p>次にportの指定。<br />デフォルトだとportの行はコメントアウトされているので、それをコメントイン。とりあえずデフォルトの5432にしておく。<br />port=5432<br />というかんじ。これでpostgresql.confの設定は終わり。</p>
<p>次にpg_hba.confの設定。これは接続してくるホストの許可リスト。<br />デフォルトだと、localhostのみが許可されているので、192.168.1.0ネットワーク内から接続許可するようにする。<br />host all all 192.168.1.0/24 trust<br />こんな感じの行を一番下に追加する。特定のデータベースやユーザーのみ許可したいときは<br />host dbname user address/mask trust<br />のような感じで書けばよい。詳しくはpg_hba.confに書いてある。</p>
<p>これで外部から接続できるはず。<br />外部pgAdminなどから接続できるようになるはず。</p>
<p>あ、あと注意としてファイアウォール。CentOS5はpostgresをインストールしても5432ポートは自動的には開いてくれない。ファイアーウォール設定でTPC 5432ポートを開けておく必要がある。</p>
]]></content:encoded>
			<wfw:commentRss>http://programming.jugglershu.net/wp/?feed=rss2&#038;p=638</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
