質問編集履歴

4

試したこと追加

2021/07/15 02:29

投稿

masuda-u
masuda-u

スコア0

test CHANGED
File without changes
test CHANGED
@@ -238,9 +238,35 @@
238
238
 
239
239
 
240
240
 
241
-
241
+ ### 試したこと4
242
+
242
-
243
+ postgresqlの中で「SHOW client_encoding;」コマンドを打つと、
244
+
243
-
245
+ 「SQL_ASCII」が出力されました。
246
+
247
+ おそらくclient_encodingの設定を変えればうまくいくのではと思います。
248
+
249
+ そのためにpostgresql.confを書き換える必要があるようです。
250
+
251
+ https://qiita.com/ihatov08/items/72bb5bd4feeef87e77a5
252
+
253
+ ↑を参考にして
254
+
255
+ postgresql.confの中身を
256
+
257
+ ```
258
+
259
+ #client_encoding = sql_ascii
260
+
261
+
262
+
263
+ client_encoding = utf8
264
+
265
+ ```
266
+
267
+ に書き換えましたが、SHOW client_encoding;→SQL_ASCIIは変更されませんでした。
268
+
269
+ どうやらpostgresql.confよりもpostgresql.auto.confの設定のほうが優先されるらしく、postgresql.auto.confの設定を変える方法を現在調べ中です。
244
270
 
245
271
 
246
272
 

3

試したこと追加

2021/07/15 02:29

投稿

masuda-u
masuda-u

スコア0

test CHANGED
File without changes
test CHANGED
@@ -126,6 +126,126 @@
126
126
 
127
127
 
128
128
 
129
+ ### 試したこと3
130
+
131
+ また、docker立ち上げの際のymlファイルを書き換えて下記の状態にもしましたが、dump.sql作成時の文字化けは解消されませんでした、、、
132
+
133
+
134
+
135
+ ```docker-compose.yml
136
+
137
+ db:
138
+
139
+ build: ./db #日本語用postgres dockerfile読み込み
140
+
141
+ container_name: db
142
+
143
+ ports:
144
+
145
+ - "5432:5432"
146
+
147
+ # トップレベルで指定したvolumeをマウントする
148
+
149
+ volumes:
150
+
151
+ - "dbdata:/var/lib/postgresql/data"
152
+
153
+ environment:
154
+
155
+ POSTGRES_PASSWORD: password # settings.pyで設定した値と同じにする
156
+
157
+ POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --locale=ja_JP.UTF-8" # ←追記 Localeの初期値
158
+
159
+ ```
160
+
161
+ と設定ファイルを書き換えて得られたものが↓
162
+
163
+ ```PowerShell
164
+
165
+ List of databases
166
+
167
+ Name | Owner | Encoding | Collate | Ctype | Access privileges
168
+
169
+ -----------+----------+----------+-------------+-------------+-----------------------
170
+
171
+ postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
172
+
173
+ template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres +
174
+
175
+ | | | | | postgres=CTc/postgres
176
+
177
+ template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres +
178
+
179
+ | | | | | postgres=CTc/postgres
180
+
181
+ (3 rows)
182
+
183
+ ```
184
+
185
+ ### 試したこと4
186
+
187
+ ```docker-compose.yml
188
+
189
+ db:
190
+
191
+ image: postgres:11
192
+
193
+ container_name: db
194
+
195
+ ports:
196
+
197
+ - "5432:5432"
198
+
199
+ # トップレベルで指定したvolumeをマウントする
200
+
201
+ volumes:
202
+
203
+ - "dbdata:/var/lib/postgresql/data"
204
+
205
+ environment:
206
+
207
+ POSTGRES_PASSWORD: password # settings.pyで設定した値と同じにする
208
+
209
+ POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --locale=C" # ←追記 Localeの初期値
210
+
211
+ ```
212
+
213
+ と設定ファイルを書き換えて得られたものが↓
214
+
215
+ ```PowerShell
216
+
217
+ List of databases
218
+
219
+ Name | Owner | Encoding | Collate | Ctype | Access privileges
220
+
221
+ -----------+----------+----------+---------+-------+-----------------------
222
+
223
+ postgres | postgres | UTF8 | C | C |
224
+
225
+ template0 | postgres | UTF8 | C | C | =c/postgres +
226
+
227
+ | | | | | postgres=CTc/postgres
228
+
229
+ template1 | postgres | UTF8 | C | C | =c/postgres +
230
+
231
+ | | | | | postgres=CTc/postgres
232
+
233
+ (3 rows)
234
+
235
+ ```
236
+
237
+ この状態でもdump.sql作成時の解消されませんでした、、、
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+ ### 補足情報
248
+
129
249
  また、
130
250
 
131
251
  docker-compose exec db bash (Docker上のPostgreSQLコンテナに入る)
@@ -150,7 +270,7 @@
150
270
 
151
271
 
152
272
 
153
- ### 補足情報
273
+ ### 補足情報2
154
274
 
155
275
 
156
276
 
@@ -160,7 +280,7 @@
160
280
 
161
281
 
162
282
 
163
- ### 補足情報2
283
+ ### 補足情報3
164
284
 
165
285
  dump.sqlの中身は↓です。
166
286
 

2

修正

2021/07/08 01:21

投稿

masuda-u
masuda-u

スコア0

test CHANGED
File without changes
test CHANGED
@@ -96,13 +96,13 @@
96
96
 
97
97
  psql postgres (データベースに入る)
98
98
 
99
- \encoding
99
+ \l
100
100
 
101
101
 
102
102
 
103
103
  上の手順で下記結果が得られました。
104
104
 
105
- ```
105
+ ```PowerShell
106
106
 
107
107
  List of databases
108
108
 
@@ -126,6 +126,28 @@
126
126
 
127
127
 
128
128
 
129
+ また、
130
+
131
+ docker-compose exec db bash (Docker上のPostgreSQLコンテナに入る)
132
+
133
+ su - postgres (ルートユーザーをpostgresに変更)
134
+
135
+ psql postgres (データベースに入る)
136
+
137
+ \encoding
138
+
139
+
140
+
141
+ では下記の結果が得られました。
142
+
143
+ ```PowerShell
144
+
145
+ SQL_ASCII
146
+
147
+ ```
148
+
149
+
150
+
129
151
 
130
152
 
131
153
  ### 補足情報

1

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

2021/07/07 00:45

投稿

masuda-u
masuda-u

スコア0

test CHANGED
File without changes
test CHANGED
@@ -74,7 +74,7 @@
74
74
 
75
75
  バックアップ時のコマンドを変えてみました(-E SJISを追加)
76
76
 
77
- ```
77
+ ```PowerShell
78
78
 
79
79
  docker-compose exec db pg_dumpall -U postgres -E SJIS > dump.sql
80
80
 
@@ -84,12 +84,62 @@
84
84
 
85
85
 
86
86
 
87
+ ### 試したこと2
88
+
89
+ データベースのコンテナに入り、エンコーディングを確認しました。
87
90
 
88
91
 
92
+
93
+ docker-compose exec db bash (Docker上のPostgreSQLコンテナに入る)
94
+
95
+ su - postgres (ルートユーザーをpostgresに変更)
96
+
89
- ### 補足情報(FW/ツルのバジョンなど)
97
+ psql postgres (デタベスに入る)
98
+
99
+ \encoding
100
+
101
+
102
+
103
+ 上の手順で下記結果が得られました。
104
+
105
+ ```
106
+
107
+ List of databases
108
+
109
+ Name | Owner | Encoding | Collate | Ctype | Access privileges
110
+
111
+ -----------+----------+----------+------------+------------+-----------------------
112
+
113
+ postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
114
+
115
+ template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
116
+
117
+ | | | | | postgres=CTc/postgres
118
+
119
+ template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
120
+
121
+ | | | | | postgres=CTc/postgres
122
+
123
+ (3 rows)
124
+
125
+ ```
126
+
127
+
128
+
129
+
130
+
131
+ ### 補足情報
90
132
 
91
133
 
92
134
 
93
135
  下記サイトを参考にしました。
94
136
 
95
137
  https://qiita.com/dtan4/items/5147a3f858d5919965c9
138
+
139
+
140
+
141
+ ### 補足情報2
142
+
143
+ dump.sqlの中身は↓です。
144
+
145
+ https://github.com/masuda-u/dockerPostgresql/blob/main/dump.sql