What a Database Server Is, and What Localhost Means
SQLite is a file. PostgreSQL and MySQL are servers. That difference confuses many beginners, along with words like localhost and port. This page untangles them.
A server is a program that waits
A database server is a program that runs in the background, waiting for other programs to connect and send queries. PostgreSQL, MySQL and SQL Server all work this way. Your app is a client: it connects to the server, sends SQL and receives results.
SQLite is different. There is no separate program; the SQLite library inside your app reads and writes the database file directly. That is why SQLite needs no installation or password.
Host: which computer?
To connect to a server, your app needs to know which computer it runs on. That is the host.
localhostmeans "this same computer". When you install PostgreSQL on your laptop and connect from a program on your laptop, the host islocalhost.127.0.0.1is the numeric address that usually means the same thing.- For a hosted database, the host is a name your provider gives you, such as
db.example-provider.com.
Port: which door?
One computer can run many server programs, so each listens on a numbered port. The usual defaults:
| Database | Default port |
|---|---|
| PostgreSQL | 5432 |
| MySQL | 3306 |
| SQL Server | 1433 |
If your server uses the default, you can often leave the port out of the connection settings.
Putting it together
A connection string combines these with a user, password and database name:
postgresql://learner:secret@localhost:5432/practice
Read it as: connect as user learner, with password secret, to the server on this computer at port 5432, and use the database called practice. In real projects, keep the password out of code; see keeping a connection string in an environment variable.
Why "connection refused" happens
This error means nothing answered at that host and port. Common reasons:
- The server is not running. Start it from your system's services or the database's installer tools.
- The port is different from what you typed.
- The host is wrong, for example
localhostwhen the database runs inside a container or on another machine.
One server, many databases
A single PostgreSQL or MySQL server can hold several separate databases, such as practice and homework. The database name in your connection settings picks one. A common mistake is creating tables in one database and querying another.
A quick self-check
| Question | Answer for SQLite | Answer for PostgreSQL on your laptop |
|---|---|---|
| Is there a server program? | No | Yes |
| What is the host? | Not needed; you give a file path | localhost |
| What is the port? | Not needed | 5432 by default |
| Do I need a password? | No | Usually yes |
For a gentle walk through every part of a connection string, see reading a connection string piece by piece.
A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.