🐈

postgresqlに接続するとSSLが有効になってないため弾かれる場合の対処方法

2022/10/30に公開

はじめに

golang-migratepostgresqlに接続してmigrateを試みたところ、以下のエラーが発生した。

調べたところ、postgresコンテナーがデフォルトで SSL を有効にしないために起こるとのことだったので対処方法をまとめる。

migrate -path db/migration -database "postgresql://username:password@localhost:5432/dbname" -verbose up
2022/10/30 17:19:16 error: pq: SSL is not enabled on the server

https://www.postgresql.jp/docs/9.2/libpq-ssl.html

https://github.com/golang-migrate/migrate/tree/master/cmd/migrate

対処方法

?sslmode=disableをデータベースURLに追加することで接続が可能になります

migrate -path db/migration -database "postgresql://username:password@localhost:5432/dbname?sslmode=disable" -verbose up

2022/10/30 17:21:06 Start buffering 1/u init_schema
2022/10/30 17:21:06 Read and execute 1/u init_schema
2022/10/30 17:21:06 Finished 1/u init_schema (read 9.189788ms, ran 32.894114ms)
2022/10/30 17:21:06 Finished after 50.370077ms
2022/10/30 17:21:06 Closing source and database
GitHubで編集を提案

Discussion