Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
PostgreSQL Automatically create Functions when a database is created

I have a requirement where I have to create a new database in PostgreSQL server for every user that signs in. Hence 1 database per user. Also, that database will have few custom defined functions that will be called. I want to automate this process of creating the custom defined functions as soon as I create a database. So that I don't have to explicitly go and execute the function in each database.

Is this possible?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

From docs:

CREATE DATABASE actually works by copying an existing database. By default, it copies the standard system database named template1. Thus that database is the "template" from which new databases are made. If you add objects to template1, these objects will be copied into subsequently created user databases. This behavior allows site-local modifications to the standard set of objects in databases. For example, if you install the procedural language PL/Perl in template1, it will automatically be available in user databases without any extra action being taken when those databases are created.

So you can create "default" objects in template1 db and "clone" it. Or you can create all needed relations (tables, functions, etc) in sample database and then "clone" it with

create database new_db with template sample_db;

Same way you can create several template databases with different "default" pre-created objects and just "clone" them as needed.

Read docs above about limitations etc.

Update Adding Postgres Objects to Template1 will show you how to do it with pgadmin

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda