Write a Python program that connects to a PostgreSQL database, retrieves all records from a specified table, and prints them out in a formatted manner. The program should also allow users to insert new records into the table.
PLAINFORMAT
import psycopg2

def connect_to_db():
    connection = psycopg2.connect(
        host="your_host",
        database="your_database",
        user="your_user",
        password="your_password"
    )
    return connection

def get_all_records(table_name):
    conn = connect_to_db()
    cursor = conn.cursor()

    query = f"SELECT * FROM {table_name};"
    cursor.execute(query)

    rows = cursor.fetchall()
    for row in rows:
        print(row)

    cursor.close()
    conn.close()

def insert_record(table_name, columns, values):
    conn = connect_to_db()
    cursor = conn.cursor()

    column_names = ', '.join(columns)
    placeholders = ', '.join(['%s'] * len(values))

    query = f"INSERT INTO {table_name} ({column_names}) VALUES ({placeholders});"
    cursor.execute(query, values)

    conn.commit()
    cursor.close()
    conn.close()

if __name__ == "__main__":
    table_name = "your_table"

    # Retrieve and print all records from the table
    print("All records:")
    get_all_records(table_name)

    # Insert a new record into the table
    columns = ["column1", "column2"]
    values = ("value1", "value2")
    insert_record(table_name, columns, values)

    # Print updated records
    print("\nUpdated records:")
    get_all_records(table_name)