Set application_name to 'pgloader' by default.

It's always been possible to set application_name to anything really,
making it easier to follow the PostgreSQL queries made by pgloader.
Force that setting to 'pgloader' by default.

Fix #387.
This commit is contained in:
Dimitri Fontaine 2016-04-11 17:14:38 +02:00
parent 0805ee32b8
commit 31f8b5c5f0
2 changed files with 21 additions and 10 deletions

View File

@ -324,15 +324,25 @@ select i.relname,
(defun sanitize-user-gucs (gucs)
"Forbid certain actions such as setting a client_encoding different from utf8."
(append
(list (cons "client_encoding" "utf8"))
(loop :for (name . value) :in gucs
:when (and (string-equal name "client_encoding")
(not (member value '("utf-8" "utf8") :test #'string-equal)))
:do (log-message :warning
"pgloader always talk to PostgreSQL in utf-8, client_encoding has been forced to 'utf8'.")
:else
:collect (cons name value))))
(let ((gucs
(append
(list (cons "client_encoding" "utf8"))
(loop :for (name . value) :in gucs
:when (and (string-equal name "client_encoding")
(not (member value '("utf-8" "utf8") :test #'string-equal)))
:do (log-message :warning
"pgloader always talk to PostgreSQL in utf-8, client_encoding has been forced to 'utf8'.")
:else
:collect (cons name value)))))
;;
;; Now see about the application_name, provide "pgloader" if it's not
;; been overloaded already.
;;
(cond ((not (assoc "application_name" gucs :test #'string-equal))
(append gucs (list (cons "application_name" "pgloader"))))
(t
gucs))))
(defun list-reserved-keywords (pgconn)
"Connect to PostgreSQL DBNAME and fetch reserved keywords."

View File

@ -8,7 +8,8 @@ LOAD CSV
fields escaped by backslash-quote
SET work_mem to '128MB',
standard_conforming_strings to 'on'
standard_conforming_strings to 'on',
application_name to 'my app name'
BEFORE LOAD DO
$$ create extension if not exists hstore; $$,