Azure Microsoft.DBforPostgreSQL flexibleServers database collations - postgresql

I tried to create new database with different (than en_US.utf8) collation on Azure Microsoft.DBforPostgreSQL flexibleServers. CLI and Bicep gives "Internal Server Error" as a message and from Portal I cannot change the collation select input at all?
Is it really so that flexibleServers allow only en_US.utf8 collation or is there some properties that I am missing?

I tried creating azure database for PostgreSQL in Azure portal and I have not got the option to select the collation. Even when I tried to create new database, I cannot change character set and collation in portal.
Therefore, I tried to create a new database using SQL command in Azure Data Studio.
Connect postgreSQL server in Azure Data Studio. (Refer the MS document on Connect and query PostgreSQL using Azure Data Studio )
Run this query to list the supported collation and encoding.
select * from pg_collation
Once connected, enter the following SQL script to create a new database with one of the supported collations from the above query.
CREATE DATABASE testdb ENCODING='UTF8' LC_COLLATE='aa_DJ.utf8' TEMPLATE='template0';
To check the collation of newly created Database, use the following query.
select datname,datcollate from pg_database;

Related

Is it possible to rename a Cloud SQL database using the gcloud CLI?

I would like to rename a Cloud SQL database using only the gcloud CLI.
I can see that I can patch a database using the CLI. However it seems to only patch either the collation or the charset but not the database name itself.
Do you know if there is a way to achieve it with the CLI ?
If not, I will use a Cloud SQL Auth Proxy and run the ALTER command directly on the database.
I don't think, there is an in-built option to rename database using gcloud command-line.
Available option is login to database engine and alter database name using ALTER DATABASE command, if it supports in-place database alteration.
Another option is use gcloud sql to export your database to sql file, make changes to your database name and import it back to Cloud SQL instance.
If you are using Cloud SQL MySQL instance, you can use mysqldump to backup and restore with new database name or use rename table with new database name.

How to DROP tables from specific database-schema in Postgresql?

I am new to Postgresql and so far I have not found a way to drop a table from specific database. To give some context:
We are doing a synchronization from Oracle to PostgreSQL of 5 tables. In postgres I have a database SoloCopy and the schema is the default public. In the Postgresql instance we have also 2 more databases SoloSynch and postgres (the default one).
What I want to do is to select SoloCopy database and:
DROP TABLE public.table1;
When I do the above DROP statement table1 is deleted only from the database that was selected when opening SQL Query. But I want to specify the database before that and to be irrelevant from where the SQL Query was open. How can I do that?
I found an answer on my own. Setup can be found here:
Psql in Task Scheduler does not run a file script
Basically I needed to use PSQL and with the connection string there I connect to a specific DB, which I can drop the tables from. The details for PGPASSWORD and the .bat file I ended up creating are in the link above. Had to start everything from CMD and switch to psql from there.

Can't create new schema in an OVH postgres

I have a PostgreSQL server on OVH's Cloud DB and have been using its databases for my web apps.
So far so good.
I got a project where It's a requirement to have schemas. Strangely enough, I am unable to create schemas on the user with "Administrator" privileges.
I have prepared scripts using schemas, so I just need to run them on a prepared database but I need a database with schemas to run them.
Here is my process:
Create a new database
Select option "Create user"
Select option for privilages: "Administrator"
Commit configuration
Wait for database creation
Connect to database with the new config via PGAdmin
Run command create schema if not exists "vMobile";
Recieve following error:
ERROR: permission denied for database my-database-dev
SQL state: 42501
I created a ticket for this but the wait is taking too long.
Support answer
Ok, so I got a response from the OVH support and there is no option for the user to create new schemas as their CloudDB enables access only to schema public and mentioned privileges Administrator, Read/Write, Read, None are only applicable to the public schema.
Workaround
My solution to this is to create tables with schema name included in their names
like so:
Desired outcome: "vCommon"."Route"
Workaround: "public"."vCommon_Route"

Every time I create a new database it's creating a table in that database

Every time I create a new database it's creating a table in that database. I'm finding information about model databases for Microsoft SQL Server, but I can't find anything for Postgres.
You probably created that table in the template1 database.
When you create a database, Postgres doesn't really create it from scratch, it copies an existing one.
Quote from the manual
By default, the new database will be created by cloning the standard system database template1. A different template can be specified by writing TEMPLATE name.
Just connect to the template1 database and drop the table there.

Insert records to Heroku Postgres database using a rails script

I need to update a dababase from an other database... For this I need to search in existing database if the records exists, if not add... One of the database is locally stored in my computer, and the other one is on heroku... But I don't know how to access heroku database from my computer to create the inserts and to query if I have to insert or not...
Any idea how can I do something like this?
You can connect via any DB tool, e.g. Oracle SQL Developer with Postgres JDBC connector, to a Heroku Postgres DB. The parameters are listed in the GUI of postgres.heroku.com for your instance.