patternsqlMinor
Extension created for public schema not available within database
Viewed 0 times
availablecreatedpublicextensionwithindatabasefornotschema
Problem
So, I create the
So, you can see that the extension is there, but once I connect to the database, it's not available anymore and I basically have to install it within the database. Any ideas how to make it available initially for the database as well?
PgSQL
citext extension for schema public and I can see it's there, but then it's not available within the database in that schema. The database is in public as well, because it's created from the postgres user and no schema is specified at the creation. Here's a screenshot with some more data:So, you can see that the extension is there, but once I connect to the database, it's not available anymore and I basically have to install it within the database. Any ideas how to make it available initially for the database as well?
PgSQL
v9.6Solution
Short answer
You are actually using (at least) two databases. You are installing
Longer answer
In the first database (whose name is not shown), you install
Then you use the
That is, you should do:
If you need to use the
Every PostgreSQL cluster (=database installation) has (by default) one database named
Within every PostgreSQL database, there is, by default, one public schema.
PostgreSQL does not work like (for instance) MySQL, where you can acces several databases at once through a single connection (provided you have a user with the right permissions).
In PostgreSQL you access one database through a single connection. Within a database, you can access as many schemas as needed. The role that schemas play in PostgreSQL is nearly the same as the one played by a database in MySQL.
See also:
You are actually using (at least) two databases. You are installing
CITEXT in the wrong one.Longer answer
In the first database (whose name is not shown), you install
CITEXT. This database is probably the postgres database, which is created by default when you install PostgreSQL.Then you use the
\c command and you switch to another database (sensordata). You need to create your extension in this database. That is, you should do:
\c sensordata
CREATE EXTENSION citext;
\dxIf you need to use the
citext module in more databases, you need to install it in each one. The extensions on the other databases don't matter. Databases do not interfere with each other.Every PostgreSQL cluster (=database installation) has (by default) one database named
postgres. If you use psql, it is the one to which you connect "by default". You don't actually need to have a postgres database. I guess the postgresdatabase is where you installed the CITEXT extension.Within every PostgreSQL database, there is, by default, one public schema.
PostgreSQL does not work like (for instance) MySQL, where you can acces several databases at once through a single connection (provided you have a user with the right permissions).
In PostgreSQL you access one database through a single connection. Within a database, you can access as many schemas as needed. The role that schemas play in PostgreSQL is nearly the same as the one played by a database in MySQL.
See also:
- Relationship between catalog, schema, user, and database instance
- What's the difference between a catalog and a schema in a relational database?
Code Snippets
\c sensordata
CREATE EXTENSION citext;
\dxContext
StackExchange Database Administrators Q#173269, answer score: 3
Revisions (0)
No revisions yet.