<?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>PostgreSQL | Men of Letters（メン・オブ・レターズ） &#8211; 論理的思考/業務改善/プログラミング</title>
	<atom:link href="https://laboratory.kazuuu.net/category/postgresql/feed/" rel="self" type="application/rss+xml" />
	<link>https://laboratory.kazuuu.net</link>
	<description></description>
	<lastBuildDate>Sat, 11 Jun 2022 20:41:12 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://laboratory.kazuuu.net/wp-content/uploads/2021/02/cropped-L-32x32.png</url>
	<title>PostgreSQL | Men of Letters（メン・オブ・レターズ） &#8211; 論理的思考/業務改善/プログラミング</title>
	<link>https://laboratory.kazuuu.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/>
<atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/>
<atom:link rel="hub" href="https://websubhub.com/hub"/>
<atom:link rel="self" href="https://laboratory.kazuuu.net/category/postgresql/feed/"/>
	<item>
		<title>データサイエンスノートブック「Deepnote」にHerokuでセットアップしたPostgreSQLデータベースを接続する</title>
		<link>https://laboratory.kazuuu.net/connect-the-postgresql-database-to-the-data-science-notebook-deepnote/</link>
					<comments>https://laboratory.kazuuu.net/connect-the-postgresql-database-to-the-data-science-notebook-deepnote/#respond</comments>
		
		<dc:creator><![CDATA[小林]]></dc:creator>
		<pubDate>Sat, 11 Jun 2022 20:41:12 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[データサイエンス]]></category>
		<guid isPermaLink="false">https://laboratory.kazuuu.net/?p=11951</guid>

					<description><![CDATA[データサイエンスノートブック「Deepnote」にデータベースを接続してみます。 前回、クラウドで実行できるデータサイエンスノートブック「Deepnote」にアカウント登録するという記事と、HerokuでPostgreS [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>データサイエンスノートブック「Deepnote」にデータベースを接続してみます。</p>
<p>前回、<a href="https://laboratory.kazuuu.net/register-for-an-account-in-the-data-science-notebook-deepnote-that-can-be-executed-in-the-cloud">クラウドで実行できるデータサイエンスノートブック「Deepnote」にアカウント登録する</a>という記事と、<a href="https://laboratory.kazuuu.net/setting-up-a-postgresql-database-on-heroku">HerokuでPostgreSQLデータベースをセットアップする</a>という記事を公開しましたので、この2つの内容を、今回あわせます。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-122914-1.png"><img decoding="async" class="alignnone size-medium wp-image-11952" src="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-122914-1-300x145.png" alt="" width="300" height="145" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-122914-1-300x145.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-122914-1-1024x495.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-122914-1-768x371.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-122914-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>Deepnoteのアカウントの登録を行うと、Deepnoteのダッシュボードへ移動します。移動後、右側に「Integrations」という項目がありますので、クリックします。クリックすると、「Add new integration or data source（新しい統合またはデータソースを追加する）」と表示されますので、この中から「PostgreSQL」をクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123218-1.png"><img fetchpriority="high" decoding="async" class="alignnone size-medium wp-image-11953" src="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123218-1-300x185.png" alt="" width="300" height="185" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123218-1-300x185.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123218-1-1024x632.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123218-1-768x474.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123218-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、「Configure PostgreSQL integration（PostgreSQLとの連携設定）」のウインドウが表示されますので、<a href="https://laboratory.kazuuu.net/setting-up-a-postgresql-database-on-heroku">HerokuでPostgreSQLデータベースをセットアップ</a>した際に、発行された資格情報を、このウインドウの項目に入力していきます。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123550-1.png"><img decoding="async" class="alignnone size-medium wp-image-11954" src="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123550-1-300x185.png" alt="" width="300" height="185" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123550-1-300x185.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123550-1-1024x630.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123550-1-768x472.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123550-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>上記のような形で入力できたら、ウインドウ内の下にある「Create」ボタンをクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123754-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-11955" src="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123754-1-300x129.png" alt="" width="300" height="129" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123754-1-300x129.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123754-1-1024x439.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123754-1-768x329.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-123754-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、「Integration created successfully（インテグレーションが正常に作成された）」と表示されます。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-125501.png"><img loading="lazy" decoding="async" class="alignnone wp-image-11956 size-medium" src="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-125501-300x88.png" alt="" width="300" height="88" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-125501-300x88.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-125501-1024x300.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-125501-768x225.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-125501.png 1298w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>表示後、PostgreSQLデータベースが追加されたのかどうか確認すると、追加されていることが確認できました。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-131512-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-11957" src="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-131512-1-300x138.png" alt="" width="300" height="138" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-131512-1-300x138.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-131512-1-1024x473.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-131512-1-768x355.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-28-131512-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>確認後、さらに検証のために、Heroku CLIを用いて、PostgreSQLデータベースにアクセスし、データベース内にtestというテーブルを作成し、このテーブルをDeepnoteで出力してみましたが、作成したテーブルを出力させることができました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://laboratory.kazuuu.net/connect-the-postgresql-database-to-the-data-science-notebook-deepnote/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Pythonでpsycopg2を使用しPostgreSQLテーブルを作成する</title>
		<link>https://laboratory.kazuuu.net/using-psycopg2-in-python-to-create-a-postgresql-table/</link>
					<comments>https://laboratory.kazuuu.net/using-psycopg2-in-python-to-create-a-postgresql-table/#respond</comments>
		
		<dc:creator><![CDATA[小林]]></dc:creator>
		<pubDate>Tue, 23 Nov 2021 21:35:02 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python【初歩から現場実務的なもの】]]></category>
		<guid isPermaLink="false">https://laboratory.kazuuu.net/?p=10925</guid>

					<description><![CDATA[Pythonでpsycopg2を使用しPostgreSQLテーブルを作成してみます。 今回は、psycopg2モジュールを使用します。psycopg2はPythonの標準ライブラリ、モジュールではありませんので、事前にイ [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Pythonでpsycopg2を使用しPostgreSQLテーブルを作成してみます。</p>
<p>今回は、psycopg2モジュールを使用します。psycopg2はPythonの標準ライブラリ、モジュールではありませんので、<a href="https://laboratory.kazuuu.net/installing-the-postgresql-database-adapter-psycopg2">事前にインストールする必要</a>があります。</p>

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-4" checked><label class="toc-title" for="toc-checkbox-4">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">■Python</a></li><li><a href="#toc2" tabindex="0">■psycopg2を使用しPostgreSQLテーブルを作成する</a><ol><li><a href="#toc3" tabindex="0">■コード</a></li></ol></li><li><a href="#toc4" tabindex="0">■実行・検証</a></li></ol>
    </div>
  </div>

<h2><span id="toc1">■Python</span></h2>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-8343" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-300x197.png" alt="" width="300" height="197" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-300x197.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-1024x671.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-768x503.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>今回のPythonのバージョンは、「3.8.5」を使用しています。（Windows10）（pythonランチャーでの確認）</p>
<h2><span id="toc2">■psycopg2を使用しPostgreSQLテーブルを作成する</span></h2>
<p>psycopg2を使用しPostgreSQLテーブルを作成しますが、<a href="https://laboratory.kazuuu.net/installing-postgresql-windows-10">PostgreSQLのインストールは前回行っています</a>ので、インストール直後に作成されているデータベースである「postgres」に新しいテーブルを作成してみます。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-02-093738-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10921" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-02-093738-1-300x165.png" alt="" width="300" height="165" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-02-093738-1-300x165.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-02-093738-1-1024x564.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-02-093738-1-768x423.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-02-093738-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>インストール直後後、確認のために、ローカルホスト内の「postgres」というデータベース（データベース名）を確認。</p>
<h3><span id="toc3">■コード</span></h3>
<pre>import psycopg2
from psycopg2 import Error, connect

try:
    connection = psycopg2.connect(user="postgres",password="パスワード",host="localhost",port="5432",database="postgres")

    cursor = connection.cursor()

    create_teble_query = '''CREATE TABLE test(
    ID INTEGER,
    NAME VARCHAR(10)
    );'''

    cursor.execute(create_teble_query)
    connection.commit()
    print("PostgreSQLでテーブルが正常に作成されました")

except(Exception,Error) as error:
    print("PostgreSQLへの接続中にエラーが発生しました",error)

finally:
    if connection:
        cursor.close()
        connection.close()
        print("PostgreSQLの接続が終了しました")</pre>
<p>インポートでpsycopg2を呼び出します。呼び出した後に、例外処理（try/except/finally）を使用し、connection変数を定義し、その中でpsycopg2.connect()関数を使用し、PostgreSQLデータベースインスタンスへの接続を処理します。この際にPostgreSQLデータベースのデータベース名やパスワード、ホスト名などが必要になります。これらの情報をpsycopg2.connect()関数の括弧内の引数,パラメーターとして渡します。</p>
<p>接続が行われた後に、connection.cursor()関数で、データベース操作を行うカーソルを作成し、cursor変数に格納します。</p>
<p>格納後、接続したデータベースで操作を行いますので、create_teble_query変数を定義し、テーブルを作成するためのクエリ、コマンドを記述し、格納します。今回は「test」というテーブルを作成してみます。</p>
<p>その後、cursor.execute()を使用し、接続したデータベースの操作（クエリまたはコマンド）を実行します。関数の括弧内には、create_teble_query変数を渡します。これで設定したクエリ、コマンドで操作が実行され、テーブルが作成されます。作成後、commit()で、PostgreSQLデータベースインスタンスへの接続処理を確定させます。</p>
<p>確定後、print()関数で「正常に作成されました」という文字列を出力します。</p>
<p>except節では、接続を行いErrorになった場合の処理を記述します。今回は、Errorが発生した場合に、エラーの内容と「エラーが発生しました」という文字列をprint()関数で出力されます。</p>
<p>finally節では、終了時に必ず実行される処理を記述します。cursor.close()関数でcursor変数に格納したデータベース操作を行うカーソルを閉じます。connection.close()関数でPostgreSQLデータベースインスタンスへの接続を閉じます。最後に、「接続が切断されました」という文字列をprint()関数で出力します。</p>
<h2><span id="toc4">■実行・検証</span></h2>
<p>このスクリプトを「db_table_1.py」という名前で、Pythonが実行されている作業ディレクトリ（カレントディレクトリ）に保存し、コマンドプロンプトから実行してみます。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-085844-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10926" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-085844-1-300x122.png" alt="" width="300" height="122" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-085844-1-300x122.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-085844-1-1024x417.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-085844-1-768x313.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-085844-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>実行してみると、PostgreSQLデータベースへの接続が行われ、今回指定したクエリ、コマンドでデータベース操作が実行し、print()関数で「正常に作成されました」と出力されました。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-090318-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10927" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-090318-1-300x239.png" alt="" width="300" height="239" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-090318-1-300x239.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-090318-1-1024x814.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-090318-1-768x611.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-03-090318-1.png 1249w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>出力後、SQL Shellで今回指定したデータベースにテーブルが作成されているのか確認すると、「test」というテーブルが作成されていることが確認できました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://laboratory.kazuuu.net/using-psycopg2-in-python-to-create-a-postgresql-table/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQLデータベースアダプタ「psycopg2」のインストール</title>
		<link>https://laboratory.kazuuu.net/installing-the-postgresql-database-adapter-psycopg2/</link>
					<comments>https://laboratory.kazuuu.net/installing-the-postgresql-database-adapter-psycopg2/#respond</comments>
		
		<dc:creator><![CDATA[小林]]></dc:creator>
		<pubDate>Sun, 21 Nov 2021 21:09:39 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python【初歩から現場実務的なもの】]]></category>
		<guid isPermaLink="false">https://laboratory.kazuuu.net/?p=10917</guid>

					<description><![CDATA[PostgreSQLデータベースアダプタ「psycopg2」のインストールについて解説しています。 psycopg2は、Python DB API 2.0 仕様の完全な実装と、複数のスレッドが同一の接続を共有できます。マ [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>PostgreSQLデータベースアダプタ「psycopg2」のインストールについて解説しています。</p>
<p>psycopg2は、Python DB API 2.0 仕様の完全な実装と、複数のスレッドが同一の接続を共有できます。マルチスレッドアプリケーション用に設計されている。</p>

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-6" checked><label class="toc-title" for="toc-checkbox-6">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">■Python</a></li><li><a href="#toc2" tabindex="0">■psycopg2をインストールする</a></li></ol>
    </div>
  </div>

<h2><span id="toc1">■Python</span></h2>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-8343" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-300x197.png" alt="" width="300" height="197" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-300x197.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-1024x671.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-768x503.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>今回のPythonのバージョンは、「3.8.5」を使用しています。（Windows10）（pythonランチャーでの確認）</p>
<h2><span id="toc2">■psycopg2をインストールする</span></h2>
<p>psycopg2をインストールを行いますが、今回はpipを経由してインストールを行うので、まずWindowsのコマンドプロンプトを起動します。</p>
<pre>pip install psycopg2</pre>
<p>起動後、上記のコマンドを入力し、Enterキーを押します。</p>
<p>なお、今回は、pythonランチャーを使用しており、Python Version 3.8.5にインストールを行うために、pipを使う場合にはコマンドでの切り替えを行います。</p>
<pre>py -3.8 -m pip install psycopg2</pre>
<p>切り替えるために、上記のコマンドを入力し、Enterキーを押します。</p>
<blockquote><p>Defaulting to user installation because normal site-packages is not writeable<br />
Collecting psycopg2<br />
Downloading psycopg2-2.9.1-cp38-cp38-win_amd64.whl (1.1 MB)<br />
|████████████████████████████████| 1.1 MB 819 kB/s<br />
Installing collected packages: psycopg2<br />
Successfully installed psycopg2-2.9.1</p></blockquote>
<p>Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、psycopg2が正常にインストールされたことになります。</p>
<p>なお、今回はpsycopg2のバージョン2.9.1をインストールしました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://laboratory.kazuuu.net/installing-the-postgresql-database-adapter-psycopg2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQLのインストールする（Windows 10）</title>
		<link>https://laboratory.kazuuu.net/installing-postgresql-windows-10/</link>
					<comments>https://laboratory.kazuuu.net/installing-postgresql-windows-10/#respond</comments>
		
		<dc:creator><![CDATA[小林]]></dc:creator>
		<pubDate>Sat, 20 Nov 2021 21:36:45 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<guid isPermaLink="false">https://laboratory.kazuuu.net/?p=10899</guid>

					<description><![CDATA[PostgreSQLのインストールについて解説しています。 今回は、Version14のインストールを行います。 目次 ■PC環境■ダウンロード■インストール ■PC環境 Windows 10 ■ダウンロード では、Po [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>PostgreSQLのインストールについて解説しています。</p>
<p>今回は、Version14のインストールを行います。</p>

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-8" checked><label class="toc-title" for="toc-checkbox-8">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">■PC環境</a></li><li><a href="#toc2" tabindex="0">■ダウンロード</a></li><li><a href="#toc3" tabindex="0">■インストール</a></li></ol>
    </div>
  </div>

<h2><span id="toc1">■PC環境</span></h2>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/10/スクリーンショット-2021-10-25-5-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10855" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/10/スクリーンショット-2021-10-25-5-1-290x300.png" alt="" width="290" height="300" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/10/スクリーンショット-2021-10-25-5-1-290x300.png 290w, https://laboratory.kazuuu.net/wp-content/uploads/2021/10/スクリーンショット-2021-10-25-5-1-991x1024.png 991w, https://laboratory.kazuuu.net/wp-content/uploads/2021/10/スクリーンショット-2021-10-25-5-1-768x794.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/10/スクリーンショット-2021-10-25-5-1.png 1250w" sizes="(max-width: 290px) 100vw, 290px" /></a></p>
<p>Windows 10</p>
<h2><span id="toc2">■ダウンロード</span></h2>
<p>では、PostgreSQLのインストールを行っていきますが、今回はインストーラをダウンロードし、インストールします。そのため、まずは「Download PostgreSQL &#8211; EDB Postgres（<a href="https://content-www.enterprisedb.com/downloads/postgres-postgresql-downloads">https://content-www.enterprisedb.com/downloads/postgres-postgresql-downloads</a>）」のページにアクセスします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-104701.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10901" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-104701-300x139.png" alt="" width="300" height="139" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-104701-300x139.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-104701-768x357.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-104701.png 994w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>アクセスすると、「PostgreSQL Database Download」と表示されています。この中から「Version 14」の項目の「Windows x86-64」のインストーラをダウンロードするために、「Download」の文字をクリックします。</p>
<p>クリックすると、「postgresql-14.0-1-windows-x64.exe」のファイルのダウンロードが開始されます。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-104933-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10902" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-104933-1-300x220.png" alt="" width="300" height="220" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-104933-1-300x220.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-104933-1-1024x750.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-104933-1-768x563.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-104933-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>しばらくすると、Webブラウザで指定されている保存場所に、「postgresql-14.0-1-windows-x64.exe」がダウンロードされます。</p>
<h2><span id="toc3">■インストール</span></h2>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105129-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10903" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105129-1-247x300.png" alt="" width="247" height="300" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105129-1-247x300.png 247w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105129-1-844x1024.png 844w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105129-1-768x932.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105129-1.png 1250w" sizes="(max-width: 247px) 100vw, 247px" /></a></p>
<p>ダウンロード後、「postgresql-14.0-1-windows-x64.exe」のファイルをダブルクリックします。</p>
<p>ダブルクリックすると、「<em>ユーザーアカウント制御」のウインドウが表示され「このアプリがデバイスに変更を加えることを許可しますか」と質問されますので「はい」ボタンをクリックします。</em></p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105317-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10904" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105317-1-300x240.png" alt="" width="300" height="240" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105317-1-300x240.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105317-1-1024x820.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105317-1-768x615.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105317-1.png 1249w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、PostgreSQLの「Setup」のウインドウが表示されますので、ウィザードを進めるために、「Next」ボタンをクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105537-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10905" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105537-1-300x239.png" alt="" width="300" height="239" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105537-1-300x239.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105537-1-1024x814.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105537-1-768x611.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105537-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、「Installation Directory（インストールディレクトリ）」と表示され、「Please specify the directory where PostgreSQL will be installed.（PostgreSQLをインストールするディレクトリを指定してください。）」と書かれていますので、ディレクトリを指定しますが、デフォルトのままで問題はありませんので、「Next」ボタンをクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105910-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10906" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105910-1-300x236.png" alt="" width="300" height="236" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105910-1-300x236.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105910-1-1024x806.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105910-1-768x605.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-105910-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、「Select Components（コンポーネントの選択）」と表示され、「<span style="font-weight: 400;">Select the components you want to install; clear the components you do not want to install.（</span>インストールしたいコンポーネントを選択し、インストールしたくないコンポーネントをクリアします。）」と書かれていますが、デフォルトのままで問題はありませんので、「Next」ボタンをクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-110512-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10907" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-110512-1-300x234.png" alt="" width="300" height="234" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-110512-1-300x234.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-110512-1-1024x798.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-110512-1-768x598.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-110512-1.png 1249w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、「Data Directory（データディレクトリ）」と表示され、「<span style="font-weight: 400;">Please select a directory under which to store your data.（データを保存するディレクトリを選択してください。）」と書かれていますので、PostgreSQLのデータを保存するディレクトリを選択しますが、デフォルトのままで問題はありませんので、「Next」ボタンをクリックします。</span></p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01_2-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10908" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01_2-1-300x235.png" alt="" width="300" height="235" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01_2-1-300x235.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01_2-1-1024x802.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01_2-1-768x601.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01_2-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、「Password（パスワード）」と表示され、「Please provide a password for the database superuser (posteres).（データベースのスーパーユーザー（posteres）のパスワードを入力してください。）」と書かれていますので、スーパーユーザーのパスワードを設定します。「Password」にパスワードを入力し、「Retype password」にもう1度パスワードを入力します。</p>
<p>入力後、「Next」ボタンをクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111258-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10909" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111258-1-300x242.png" alt="" width="300" height="242" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111258-1-300x242.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111258-1-1024x826.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111258-1-768x619.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111258-1.png 1249w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、「Port（ポート）」と表示され、「Please select the port number the server should listen on.（サーバーが待ち受けるポート番号を選択してください）」と書かれていますが、デフォルトで表示されている「Port 5432」で、特に問題はないので、「Next」ボタンをクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111647-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10910" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111647-1-300x239.png" alt="" width="300" height="239" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111647-1-300x239.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111647-1-1024x817.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111647-1-768x613.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-111647-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、「Advanced Options（高度なオプション）」と表示され、「Select the locale to be used by the new database cluster.（新しいデータベースクラスターで使用するロケール・場所を選択します。）」と書かれていますので、「Locale」から「Japan」も選択できますが、デフォルトの「<span style="font-weight: 400;">Default locale」で問題はないので、今回はこのままの状態で「Next」ボタンをクリックします。</span></p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112053-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10911" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112053-1-300x242.png" alt="" width="300" height="242" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112053-1-300x242.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112053-1-1024x825.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112053-1-768x619.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112053-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると「Pre Installation Summary（インストール前の概要）」が表示され、「The following settings will be used for the installation（インストールには以下の設定が使用されます。）」と書かれていますので、概要を確認し、「Next」ボタンをクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112313-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10912" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112313-1-300x237.png" alt="" width="300" height="237" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112313-1-300x237.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112313-1-1024x809.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112313-1-768x606.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112313-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、「Ready to Install（すぐにインストール）」と表示され、「Setup is now ready to begin installing PostgreSQL on your computer.（これでセットアップが完了し、お使いのコンピュータにPostgreSQLのインストールを開始できます。）」と書かれています。「Install」ボタンをクリックすると、PostgreSQLのインストールが開始されますので、クリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112605-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10913" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112605-1-300x239.png" alt="" width="300" height="239" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112605-1-300x239.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112605-1-1024x815.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112605-1-768x611.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-112605-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、「Installing（インストール中）」と表示されます。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-113028-1.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-10914" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-113028-1-300x237.png" alt="" width="300" height="237" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-113028-1-300x237.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-113028-1-1024x809.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-113028-1-768x607.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/11/スクリーンショット-2021-11-01-113028-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>インストールが開始され、しばらくすると、「Completing the PostgreSQL Setup Wizard（PostgreSQLセットアップウィザードの完了）」と表示され、これでセットアップウィザードは完了となります。完了後、「Launch Stack Builder at exit?（終了時に Stack Builder を起動しますか？<br />
）」「Stack Builder may be used to download and install additional tools, drivers and applications to complement your PostgreSQL installation.（Stack Builderは、PostgreSQLのインストールを補完するための追加ツール、ドライバ、アプリケーションをダウンロードしてインストールするために使用されます。）」のチェックボックスを外し、今回は追加ツールなどのダウンロード、インストールは行いません。</p>
<p>最後に「Finish」ボタンをクリックします。クリックすると、セットアップのウインドウが閉じます。これでインストールの作業は完了となります。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://laboratory.kazuuu.net/installing-postgresql-windows-10/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
