0% found this document useful (0 votes)
4 views2 pages

Neon PostgreSQL Guide

This document provides a step-by-step guide for connecting to a PostgreSQL database on Neon. It includes instructions for registering on Neon, creating a database, connecting to it, creating required tables, and inserting sample data. The guide emphasizes using the SQL Editor for executing SQL commands and managing database credentials through a .env file.

Uploaded by

Nikhil Chaugule
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Neon PostgreSQL Guide

This document provides a step-by-step guide for connecting to a PostgreSQL database on Neon. It includes instructions for registering on Neon, creating a database, connecting to it, creating required tables, and inserting sample data. The guide emphasizes using the SQL Editor for executing SQL commands and managing database credentials through a .env file.

Uploaded by

Nikhil Chaugule
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Step-by-Step Guide: Connecting PostgreSQL on Neon

Step 1: Register on Neon


1. Go to [Link] and sign up using your email or GitHub.

2. Verify your email and log in to your Neon dashboard.

Step 2: Create a Database


1. Click on 'New Project'.

2. Choose a name for your project and click 'Create'.

3. Once the project is created, go to the 'Connection' tab to find your database credentials.

Step 3: Connect to Database


1. Copy the database connection string from the 'Connection' tab.
2. It will look like: postgresql://user:password@host:port/dbname
3. Create a `.env` file with your Neon database credentials:

DB_DATABASE=your_db_name
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=your_db_host
DB_PORT=your_db_port

Step 4: Create Required Tables


1. Go to SQL Editor Tab that left side of website
2. Run the following SQL commands to create the necessary tables:

CREATE TABLE sensor_data (


id SERIAL PRIMARY KEY,
temperature FLOAT NOT NULL,
gas_level FLOAT NOT NULL,
light_intensity BOOLEAN NOT NULL,
fire_detected BOOLEAN NOT NULL,
fan_status BOOLEAN NOT NULL,
led_status BOOLEAN NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Step 5: Insert Sample Data


1. Go to SQL Editor Tab that left side of website
2. Run the following SQL commands to insert sample data:

INSERT INTO sensor_data (temperature, gas_level, light_intensity, fire_detected,


fan_status, led_status)
VALUES (25.5, 40.2, TRUE, FALSE, FALSE, TRUE);

INSERT INTO users (username, password)


VALUES ('admin', 'admin');

You might also like