我有一个比较大的表(大约30gbs),我想从Postgres转移到S3。我正试图了解像io.BytesIO()
这样的文件是如何工作的,我需要在机器上提供多少内存才能更好地设计代码
我使用aiobotcore将数据移动到s3,使用asyncpg查询Postgres。为了更好地解释这个问题,我制作了一个示例演示
import asyncio
import asyncpg
import io
import aiobotocore
async def happy_demo():
# Define the connection to Postgres
con = await asyncpg.connect(**postgres_credentials)
# Get a handle onto an aiobotocore session
session = aiobotocore.get_session()
# Create file-like object
file = io.BytesIO()
# Create the S3 client
async with session.create_client(**aws_credentials) as client:
# Create a gzip file
with gzip.GzipFile(fileobj=file, mode='wb') as gz:
await con.copy_from_query(query='select * from bar', output=gz, format='csv')
# Write to S3
await client.put_object(Bucket="happy_bucket", Key="foo.csv", Body=file.getvalue())
# Close the connection.
await con.close()
def main():
loop = asyncio.get_event_loop()
loop.run_until_complete(happy_demo())
if __name__ == '__main__':
main()
特别是,我试图理解,如果表大小在30gb左右,我是否需要一台至少有30gb ram的机器才能执行此操作
我已经更新了我的代码(包括gzip文件),并稍微重新格式化了我的问题以包括gzip
目前没有回答
相关问题 更多 >
编程相关推荐