Saltar al contenido

instalar postgresql 9.5 ubuntu 20.04 código de ejemplo

Nuestro grupo de especialistas luego de muchos días de trabajo y de recopilar de información, han obtenido la respuesta, queremos que te sea útil en tu proyecto.

Ejemplo 1: instalar postgresql ubuntu 20.04

Step 1 — Installing PostgreSQL
To install PostgreSQL,first refresh your server’s local package index:

sudo apt updateThen, install the Postgres package along with a -contrib package that adds some additional utilities and functionality:

sudo apt install postgresql postgresql-contrib
 
Step 2Using PostgreSQL Roles andDatabasesBydefault, Postgres uses a concept called “roles” to handle authentication andauthorization. These are,insome ways, similar to regular Unix-style users and groups.

Upon installation, Postgres isset up touse ident authentication, meaning that it associates Postgres roles with a matching Unix/Linux system account.If a role existswithin Postgres, a Unix/Linux username with the same name is able to sign inas that role.

The installation procedure created a user account called postgres that is associated with the default Postgres role. There are a few ways to utilize this account to access Postgres. One way isto switch overto the postgres account on your server by typing:

sudo -i -u postgres
 
Then you can access the Postgres prompt by typing:

psql
 
This will log you into the PostgreSQL prompt,andfrom here you are free to interact with the database management system right away.Toexitoutof the PostgreSQL prompt, run the following:

q
 
This will bring you back to the postgres Linux command prompt.Toreturnto your regular system user, run the exit command:

exit
 
Another way toconnectto the Postgres prompt isto run the psql command as the postgres account directly with sudo:

sudo -u postgres psql
 
This will log you directly into Postgres without the intermediary bash shell inbetween.

Again, you can exit the interactive Postgres sessionby typing:

q
 
Step 3 — Creating a New Role
If you are logged inas the postgres account, you can create a new role by typing:

createuser --interactiveIf, instead, you prefer touse sudo for each command without switching from your normal account,type:

sudo -u postgres createuser --interactive
 
Either way, the script will prompt you withsome choices and, based on your responses,execute the correct Postgres commands tocreate a userto your specifications.

Output
Enter name of role toadd: sammy
Shall the new role be a superuser? (y/n) y
Step 4 — Creating a New Database
Another assumption that the Postgres authentication system makes bydefaultis that forany role used to log in, that role will have a databasewith the same name which it can access.

This means that if the user you created in the last section is called sammy, that role will attempt toconnectto a database which is also called “sammy” bydefault. You can create the appropriate databasewith the createdb command.If you are logged inas the postgres account, you would type something like:

createdb sammy
 
If, instead, you prefer touse sudo for each command without switching from your normal account, you would type:

sudo -u postgres createdb sammy
 
Step 5 — Opening a Postgres Prompt with the New Role
To log inwith ident based authentication, you’ll need a Linux userwith the same name as your Postgres role anddatabase.If you don’t have a matching Linux user available, you can create one with the adduser command. You will have todo this from your non-root account with sudo privileges(meaning,not logged inas the postgres user):

sudo adduser sammy
 
Once this new account is available, you can either switch overandconnectto the databaseby typing:

sudo -i -u sammy
psql
 
Or, you can do this inline:

sudo -u sammy psql
 
This command will log you in automatically, assuming that allof the components have been properly configured.If you want your usertoconnectto a different database, you can do so by specifying the databaselike this:

psql -d postgres
 
Once logged in, you can get check your current connection information by typing:

conninfo
 
Output
You are connected todatabase"sammy"asuser"sammy" via socket in"/var/run/postgresql" at port "5432".
Conclusion
You are now set up with PostgreSQL on your Ubuntu 20.04 server.If you’d liketo learn more about Postgres and how touse it, we encourage you tocheckout the following guides:

Ejemplo 2: instalar postgresql ubuntu 20.04

please click on this link.

https://linuxhint.com/install_postgresql_-ubuntu/

Sección de Reseñas y Valoraciones

Ten en cuenta dar recomendación a este ensayo si lograste el éxito.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *