teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

試したこと追加

2021/07/15 02:29

投稿

masuda-u
masuda-u

スコア0

title CHANGED
File without changes
body CHANGED
@@ -118,9 +118,22 @@
118
118
  ```
119
119
  この状態でもdump.sql作成時の解消されませんでした、、、
120
120
 
121
+ ### 試したこと4
122
+ postgresqlの中で「SHOW client_encoding;」コマンドを打つと、
123
+ 「SQL_ASCII」が出力されました。
124
+ おそらくclient_encodingの設定を変えればうまくいくのではと思います。
125
+ そのためにpostgresql.confを書き換える必要があるようです。
126
+ https://qiita.com/ihatov08/items/72bb5bd4feeef87e77a5
127
+ ↑を参考にして
128
+ postgresql.confの中身を
129
+ ```
130
+ #client_encoding = sql_ascii
131
+
132
+ client_encoding = utf8
133
+ ```
134
+ に書き換えましたが、SHOW client_encoding;→SQL_ASCIIは変更されませんでした。
135
+ どうやらpostgresql.confよりもpostgresql.auto.confの設定のほうが優先されるらしく、postgresql.auto.confの設定を変える方法を現在調べ中です。
121
136
 
122
-
123
-
124
137
  ### 補足情報
125
138
  また、
126
139
  docker-compose exec db bash (Docker上のPostgreSQLコンテナに入る)

3

試したこと追加

2021/07/15 02:29

投稿

masuda-u
masuda-u

スコア0

title CHANGED
File without changes
body CHANGED
@@ -62,6 +62,66 @@
62
62
  (3 rows)
63
63
  ```
64
64
 
65
+ ### 試したこと3
66
+ また、docker立ち上げの際のymlファイルを書き換えて下記の状態にもしましたが、dump.sql作成時の文字化けは解消されませんでした、、、
67
+
68
+ ```docker-compose.yml
69
+ db:
70
+ build: ./db #日本語用postgres dockerfile読み込み
71
+ container_name: db
72
+ ports:
73
+ - "5432:5432"
74
+ # トップレベルで指定したvolumeをマウントする
75
+ volumes:
76
+ - "dbdata:/var/lib/postgresql/data"
77
+ environment:
78
+ POSTGRES_PASSWORD: password # settings.pyで設定した値と同じにする
79
+ POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --locale=ja_JP.UTF-8" # ←追記 Localeの初期値
80
+ ```
81
+ と設定ファイルを書き換えて得られたものが↓
82
+ ```PowerShell
83
+ List of databases
84
+ Name | Owner | Encoding | Collate | Ctype | Access privileges
85
+ -----------+----------+----------+-------------+-------------+-----------------------
86
+ postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
87
+ template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres +
88
+ | | | | | postgres=CTc/postgres
89
+ template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres +
90
+ | | | | | postgres=CTc/postgres
91
+ (3 rows)
92
+ ```
93
+ ### 試したこと4
94
+ ```docker-compose.yml
95
+ db:
96
+ image: postgres:11
97
+ container_name: db
98
+ ports:
99
+ - "5432:5432"
100
+ # トップレベルで指定したvolumeをマウントする
101
+ volumes:
102
+ - "dbdata:/var/lib/postgresql/data"
103
+ environment:
104
+ POSTGRES_PASSWORD: password # settings.pyで設定した値と同じにする
105
+ POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --locale=C" # ←追記 Localeの初期値
106
+ ```
107
+ と設定ファイルを書き換えて得られたものが↓
108
+ ```PowerShell
109
+ List of databases
110
+ Name | Owner | Encoding | Collate | Ctype | Access privileges
111
+ -----------+----------+----------+---------+-------+-----------------------
112
+ postgres | postgres | UTF8 | C | C |
113
+ template0 | postgres | UTF8 | C | C | =c/postgres +
114
+ | | | | | postgres=CTc/postgres
115
+ template1 | postgres | UTF8 | C | C | =c/postgres +
116
+ | | | | | postgres=CTc/postgres
117
+ (3 rows)
118
+ ```
119
+ この状態でもdump.sql作成時の解消されませんでした、、、
120
+
121
+
122
+
123
+
124
+ ### 補足情報
65
125
  また、
66
126
  docker-compose exec db bash (Docker上のPostgreSQLコンテナに入る)
67
127
  su - postgres (ルートユーザーをpostgresに変更)
@@ -74,11 +134,11 @@
74
134
  ```
75
135
 
76
136
 
77
- ### 補足情報
137
+ ### 補足情報2
78
138
 
79
139
  下記サイトを参考にしました。
80
140
  https://qiita.com/dtan4/items/5147a3f858d5919965c9
81
141
 
82
- ### 補足情報2
142
+ ### 補足情報3
83
143
  dump.sqlの中身は↓です。
84
144
  https://github.com/masuda-u/dockerPostgresql/blob/main/dump.sql

2

修正

2021/07/08 01:21

投稿

masuda-u
masuda-u

スコア0

title CHANGED
File without changes
body CHANGED
@@ -47,10 +47,10 @@
47
47
  docker-compose exec db bash (Docker上のPostgreSQLコンテナに入る)
48
48
  su - postgres (ルートユーザーをpostgresに変更)
49
49
  psql postgres (データベースに入る)
50
- \encoding
50
+ \l
51
51
 
52
52
  上の手順で下記結果が得られました。
53
- ```
53
+ ```PowerShell
54
54
  List of databases
55
55
  Name | Owner | Encoding | Collate | Ctype | Access privileges
56
56
  -----------+----------+----------+------------+------------+-----------------------
@@ -62,7 +62,18 @@
62
62
  (3 rows)
63
63
  ```
64
64
 
65
+ また、
66
+ docker-compose exec db bash (Docker上のPostgreSQLコンテナに入る)
67
+ su - postgres (ルートユーザーをpostgresに変更)
68
+ psql postgres (データベースに入る)
69
+ \encoding
65
70
 
71
+ では下記の結果が得られました。
72
+ ```PowerShell
73
+ SQL_ASCII
74
+ ```
75
+
76
+
66
77
  ### 補足情報
67
78
 
68
79
  下記サイトを参考にしました。

1

List of databases追記 dump.sqlの中身を追記

2021/07/07 00:45

投稿

masuda-u
masuda-u

スコア0

title CHANGED
File without changes
body CHANGED
@@ -36,13 +36,38 @@
36
36
 
37
37
  ### 試したこと
38
38
  バックアップ時のコマンドを変えてみました(-E SJISを追加)
39
- ```
39
+ ```PowerShell
40
40
  docker-compose exec db pg_dumpall -U postgres -E SJIS > dump.sql
41
41
  ```
42
42
  これだとdump.sqlの中身は文字化けしていませんが、リストア後に日本語部分が「?」の文字になってしまいました。
43
43
 
44
+ ### 試したこと2
45
+ データベースのコンテナに入り、エンコーディングを確認しました。
44
46
 
47
+ docker-compose exec db bash (Docker上のPostgreSQLコンテナに入る)
48
+ su - postgres (ルートユーザーをpostgresに変更)
45
- ### 補足情報(FW/ツルのバジョンなど)
49
+ psql postgres (デタベスに入る)
50
+ \encoding
46
51
 
52
+ 上の手順で下記結果が得られました。
53
+ ```
54
+ List of databases
55
+ Name | Owner | Encoding | Collate | Ctype | Access privileges
56
+ -----------+----------+----------+------------+------------+-----------------------
57
+ postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
58
+ template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
59
+ | | | | | postgres=CTc/postgres
60
+ template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
61
+ | | | | | postgres=CTc/postgres
62
+ (3 rows)
63
+ ```
64
+
65
+
66
+ ### 補足情報
67
+
47
68
  下記サイトを参考にしました。
48
- https://qiita.com/dtan4/items/5147a3f858d5919965c9
69
+ https://qiita.com/dtan4/items/5147a3f858d5919965c9
70
+
71
+ ### 補足情報2
72
+ dump.sqlの中身は↓です。
73
+ https://github.com/masuda-u/dockerPostgresql/blob/main/dump.sql