Thanks for your responses and the default does appear to be SQL_ASCII on Ubuntu 20.10
OS Version:
root@netBox:/opt/netbox# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.10
Release: 20.10
Codename: groovy
Postgres Version:
postgres@netBox:/opt/netbox$ psql
psql (12.5 (Ubuntu 12.5-0ubuntu0.20.10.1))
And as you can see, the template is ASCII:
postgres@netBox:/opt/netbox$ psql --list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+-------+-----------------------
netbox | postgres | SQL_ASCII | C | C | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | netbox=CTc/postgres
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
In addition, it looks like my locale should have set it appropriately.
root@netBox:/opt/netbox# locale -a
C
C.UTF-8
POSIX
Maybe modify the instructions from:
postgres=# CREATE DATABASE netbox;
to
CREATE DATABASE netbox WITH ENCODING 'UTF8' LC_COLLATE='C.UTF-8' LC_CTYPE='C.UTF-8';
Admittedly, I know very little about the subject and postgres seems to have messed it up. I would assume if you try to set all that maybe some languages might be mangled as a result.
After following the instructions
here I ended up with:
postgres@netBox:~$ psql --list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+-------+-----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C |
And since that didn't match yours exactly I decided to change the collate and Ctype as well. I would assume that they are just contacted with the Encoding so it wouldn't matter but just to be sure. Since this container is only going to be used for netBox I decided to change the default template in case some future process had to create another DB. I found
the same How To article was really helpful. The "AS integer" replacement was mentioned in
the How To article so I thought to be safe, I should run that as well.
Because mine was slightly different and for future Googlers, below are the steps I used and the output:
postgres@netBox:~$ pg_dump netbox > netbox-dump.sql
postgres@netBox:~$ sed 's/AS integer//' netbox-dump.sql > alt-netbox-dump.sql
postgres@netBox:~$ ls
12 alt-netbox-dump.sql netbox-dump.sql
postgres@netBox:~$ exit
root@netBox:~# systemctl stop netbox.service netbox-rq.service
nginx.service
root@netBox:~# su postgres
postgres@netBox:~$ dropdb netbox
postgres@netBox:~$ psql
psql (12.5 (Ubuntu 12.5-0ubuntu0.20.10.1))
Type "help" for help.
UPDATE 1
postgres=# DROP DATABASE template1;
DROP DATABASE
postgres=# CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE='C.UTF-8' LC_CTYPE='C.UTF-8';
CREATE DATABASE
postgres=# UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
UPDATE 1
postgres=# \c template1;
You are now connected to database "template1" as user "postgres".
template1=# VACUUM FREEZE;
VACUUM
postgres@netBox:~$ psql --list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+---------+-----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
postgres@netBox:~$ psql
psql (12.5 (Ubuntu 12.5-0ubuntu0.20.10.1))
Type "help" for help.
postgres=# CREATE DATABASE netbox;
CREATE DATABASE
postgres=# \q
postgres@netBox:~$ psql --list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+---------+-----------------------
netbox | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
postgres@netBox:~$ psql netbox < alt-netbox-dump.sql
postgres@netBox:~$ psql
postgres=# GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;
GRANT
root@netBox:~# systemctl stop netbox.service netbox-rq.service
nginx.service
I doubt I needed to run the GRANT statement again as I didn't drop the user but I didn't know if dropping the DB would wipe the privileges associated with it so I just ran it to make sure.
Tested and all works. The funny thing is, what I was trying to do I shouldn't have been doing anyway. I was trying to add an SFP as a device type which of course isn't correct.
Thanks a ton for your help.
--